Pyhon DirectInput 鼠标相对移动行为不符合预期 [英] Pyhon DirectInput Mouse Relative Moving act not as expected

查看:100
本文介绍了Pyhon DirectInput 鼠标相对移动行为不符合预期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了通过 DirectInput 模拟鼠标移动的解决方案.重点是使用python脚本在3D游戏中导航角色.这意味着必须使用相对鼠标移动.

I found solution to emulate mouse movement by DirectInput. Point is to use python script to navigate character in 3D Game. That means that have to use relative mouse movement.

一切正常,但是当我尝试计算 x Units 之间的关系(在 MouseMoveTo 函数中)和 Angle 游戏中的角色转弯时,我发现 算术做到了效果不好.

Everything was working but when i try calculate relationship between x Units (in MouseMoveTo function) and Angle character turn in game, I found out that aritmetics did not work well.

例如:

当我移动鼠标 向左移动 2 x 200 单位 然后 向右移动 1 x 400 单位 字符不看同一个方向(如果在桌面,光标不在同一个位置)

When i move mouse 2 x 200 Units Left then 1 x 400 Units Right character not looking at same direction (cursor is not at same place if in desktop)

2x200 <1x400

如果我尝试为运动设置动画(例如将运动分成 50 步),情况会变得更糟.

If i try to animate movement (for example divide movement to 50 steps), it gets even worse.

我做错了什么还是正常行为?如果这是正常行为,有什么办法可以计算出正确传递给 MouseMove To() 的单位数吗?

Am i doing something wrong or it is normal behavior? if it is normal behavior, is there any way i can calculate to correct number of units passing to MouseMove To()?

import ctypes
import time

# C struct redefinitions 
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
    _fields_ = [("wVk", ctypes.c_ushort),
                ("wScan", ctypes.c_ushort),
                ("dwFlags", ctypes.c_ulong),
                ("time", ctypes.c_ulong),
                ("dwExtraInfo", PUL)]

class HardwareInput(ctypes.Structure):
    _fields_ = [("uMsg", ctypes.c_ulong),
                ("wParamL", ctypes.c_short),
                ("wParamH", ctypes.c_ushort)]

class MouseInput(ctypes.Structure):
    _fields_ = [("dx", ctypes.c_long),
                ("dy", ctypes.c_long),
                ("mouseData", ctypes.c_ulong),
                ("dwFlags", ctypes.c_ulong),
                ("time",ctypes.c_ulong),
                ("dwExtraInfo", PUL)]

class Input_I(ctypes.Union):
    _fields_ = [("ki", KeyBdInput),
                 ("mi", MouseInput),
                 ("hi", HardwareInput)]

class Input(ctypes.Structure):
    _fields_ = [("type", ctypes.c_ulong),
                ("ii", Input_I)]

# Actuals Functions
def MouseMoveTo(x, y):
    extra = ctypes.c_ulong(0)
    ii_ = Input_I()
    ii_.mi = MouseInput(x, y, 0, 0x0001, 0, ctypes.pointer(extra))

    command = Input(ctypes.c_ulong(0), ii_)
    ctypes.windll.user32.SendInput(1, ctypes.pointer(command), ctypes.sizeof(command))

推荐答案

好吧 ... 所以问题是 Windows增强指针精度"设置,简而言之,它使小(慢)鼠标移动得越来越小(快)) 更大...

Ok ... so problem was Windows "Enhance Pointer Precision" setting, which, in short, makes small (slow) mouse moves even smaller and big (fast) even bigger...

关闭后,一切正常.

在此处详细了解此窗口功能"https://www.howtogeek.com/321763/what-is-enhance-pointer-precision-in-windows/

这篇关于Pyhon DirectInput 鼠标相对移动行为不符合预期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆