GetAxis("Mouse X/Y") 不适用于虚拟鼠标

GetAxis("Mouse X/Y") does not work with virtual mouse

我最近尝试在 python 中为统一游戏编写一个机器人,以使用虚拟鼠标(如 pyautogui 或 autohotkey)来控制角色。游戏有多种相机模式。一个使用光标位置,另一个使用 GetAxis("Mouse X/Y")。我正在使用的库、pyautogui、pydirectinput,甚至自动热键宏都无法在使用 GetAxis() 的选项上移动鼠标,尽管它适用于使用光标位置的相机。为什么会这样? 使用 GetAxis() 时失败的脚本示例: Yoinked 从另一个堆栈溢出 post 因为我也需要一个 ahk 示例:

CoordMode, mouse, screen

toggle := 0, fixedY := A_ScreenHeight/2 ; choose the y you like

F1::
MouseGetPos, MouseX, MouseY
if toggle := !toggle
 gosub, MoveTheMouse
else
 SetTimer, MoveTheMouse, off
return

MoveTheMouse:
Random, x, 1, % A_ScreenWidth
MouseMove, %x%, %fixedY%, 100
Random, Time, 1000*60, 1000*60*5
SetTimer, MoveTheMouse, -%time%  ; every 3 seconds 
return

用于移动的C#代码是:

case CAMERA_TYPE.CAMERA_THAT_WORKS_WITH_BOT:
                if (Input.mousePosition.x < (float)Screen.width * 0.4f)
                {
                    mainT.RotateAround(mainT.position, Vector3.up, -(((float)Screen.width * 0.4f - Input.mousePosition.x) / (float)Screen.width * 0.4f) * getSensitivityMultiWithDeltaTime() * 150f);
                }
                else if (Input.mousePosition.x > (float)Screen.width * 0.6f)
                {
                    mainT.RotateAround(mainT.position, Vector3.up, (Input.mousePosition.x - (float)Screen.width * 0.6f) / (float)Screen.width * 0.4f * getSensitivityMultiWithDeltaTime() * 150f);
                }
                mainT.rotation = Quaternion.Euler(140f * ((float)Screen.height * 0.6f - Input.mousePosition.y) / (float)Screen.height * 0.5f, mainT.rotation.eulerAngles.y, mainT.rotation.eulerAngles.z);
                mainT.position -= mainT.forward * this.distance * this.distanceMulti * this.distanceOffsetMulti;
                break;
            case CAMERA_TYPE.CAMERA_THAT_FAILS_WITH_BOT:
                if (!CustomInputs.Inputs.menuOn)
                {
                    Screen.lockCursor = true;
                }
                float num5 =0f;
                float num6 =0f;
                if (((int)GameManager.settings[300]) == 0)
                {
                    num5 = (Input.GetAxis("Mouse X") * 10f) * this.getSensitivityMulti();
                    num6 = ((-Input.GetAxis("Mouse Y") * 10f) * this.getSensitivityMulti()) * this.getReverse();
                }
                else if (((int)GameManager.settings[300]) == 1)
                {
                    num5 = (Input.GetAxisRaw("Mouse X") * 10f) * this.getSensitivityMulti();
                    num6 = ((-Input.GetAxisRaw("Mouse Y") * 10f) * this.getSensitivityMulti()) * this.getReverse();
                }

                mainT.RotateAround(mainT.position, Vector3.up, num5);
                float num7 = mainT.rotation.eulerAngles.x % 360f;
                float num8 = num7 + num6;
                if (((num6 <= 0f) || (((num7 >= 260f) || (num8 <= 260f)) && ((num7 >= 80f) || (num8 <= 80f)))) && ((num6 >= 0f) || (((num7 <= 280f) || (num8 >= 280f)) && ((num7 <= 100f) || (num8 >= 100f)))))
                {
                    mainT.RotateAround(mainT.position, mainT.right, num6);
                }
                mainT.position -= (Vector3)(((mainT.forward * this.distance) * this.distanceMulti) * this.distanceOffsetMulti);
                break;

由于反编译,部分代码无法理解。另外请注意,不要担心这里的模组,因为游戏基本上已经被开发者放弃了 4 年,现在 运行 在社区服务器上。

经过进一步搜索,我发现 GetAxis 可能会使用鼠标 velocity/acceleration,我认为这些鼠标移动功能不会以任何方式影响它。在我的用例中,我需要测试的是一种读取鼠标 acceleration/velocity 的方法和一种移动鼠标 acceleration/velocity 的方法。请让我知道我是否有正确的想法,如有任何与此相关的 material 参考,我们将不胜感激。

我找到的修复方法是使用 windows dll 调用: AHK:

DllCall("mouse_event", "UInt", 0x01, "UInt", 100, "UInt", 100)

python:

import ctypes
ctypes.windll.user32.mouse_event(0x01, x, y, 0, 0)