程序可防止鼠标移动

a.j*_*eed 8 python winapi python-3.x

我有一个游戏的点击机器人,并没有使用它一段时间.我安装了新的(可能有一个新版本),我的机器人不再工作了.当游戏被激活时,事件似乎以某种方式被阻止.

我通过以下方式激活游戏:

shell=win32com.client.Dispatch("Wscript.Shell")
success = shell.AppActivate("Game)
Run Code Online (Sandbox Code Playgroud)

我尝试了两种移动鼠标的方法:

win32api.SetCursorPos((x,y)) 
Run Code Online (Sandbox Code Playgroud)

这给了我这个错误.

pywintypes.error: (0, 'SetCursorPos', 'No error message is available')
Run Code Online (Sandbox Code Playgroud)

另一种方法是:

nx = int(x*65535/win32api.GetSystemMetrics(0))
ny = int(y*65535/win32api.GetSystemMetrics(1))
win32api.mouse_event(win32con.MOUSEEVENTF_ABSOLUTE|win32con.MOUSEEVENTF_MOVE,nx,ny)
Run Code Online (Sandbox Code Playgroud)

这不起作用,并没有给我一个错误信息.

当游戏窗口未激活时,光标移动没有问题.

有人知道解决方法吗?

编辑:我正在使用Microsoft Windows 8.1

a.j*_*eed 5

我尝试了ctypes,这有效:

ctypes.windll.user32.SetCursorPos(x, y)
Run Code Online (Sandbox Code Playgroud)