检测模拟键盘/鼠标输入

发布于 2024-10-09 13:36:36 字数 151 浏览 3 评论 0原文

有没有办法检测 Windows 上的模拟键盘/鼠标输入。例如,用户在键盘上与 sendKeys/PostMessage/屏幕键盘上键入内容。有什么方法可以区分两者吗?

编辑:也许一个例子会有所帮助。我正在制作一个游戏,想要区分真实输入与合成键盘/鼠标消息的 WinAPI。

Is there a way to detect simulated keyboard/mouse input on Windows. For example, a user types something on his keyboard vs sendKeys/PostMessage/On-screen keyboard. Is there a way that I can distinguish between the two?

EDIT: Perhaps an example would help. I am making a game and want to distinguish between real input vs WinAPI synthesizing keyboard/mouse messages.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纵山崖 2024-10-16 13:36:36

区分“真实”输入和“模拟”输入的唯一方法(假设它是使用 keybd_event()/mouse_event()SendInput() 生成的)是通过SetWindowsHookEx()使用低级键盘/鼠标钩子。 WH_KEYBOARD_LLWH_MOUSE_LL 挂钩回调为模拟输入提供 INJECTED 标志。

The only way to distinguish between "real" input and "simulated" input (assuming it is being generated with keybd_event()/mouse_event() or SendInput()) is to use a low-level keyboard/mouse hook via SetWindowsHookEx(). The WH_KEYBOARD_LL and WH_MOUSE_LL hook callbacks provide INJECTED flags for simulated input.

安静 2024-10-16 13:36:36

从 Windows 8 开始,有 GetCurrentInputMessageSource< /code>函数。您可以使用它,并检查 originId 枚举中的以下值:

IMO_INJECTED - 输入消息已由未设置 UIAccess 属性的应用程序注入(通过 SendInput 函数)在其清单文件中设置为 TRUE

Starting form Windows 8 there's the GetCurrentInputMessageSource function. You can use it, and check the originId enum for the following value:

IMO_INJECTED - The input message has been injected (through the SendInput function) by an application that doesn't have the UIAccess attribute set to TRUE in its manifest file.

此生挚爱伱 2024-10-16 13:36:36

我可能是错的,但屏幕键盘(以及其他模拟用户输入的应用程序)很可能使用 SendInput API:

SendInput 在输入堆栈的底层进行操作。它只是键盘和鼠标驱动程序用来告诉窗口管理器用户已生成输入的同一输入机制的后门。
来源:http://blogs.msdn.com/b /oldnewthing/archive/2010/12/21/10107494.aspx

因此,可能无法判断输入是否来自“真实”键盘。

I might be wrong, but the on-screen keyboard (and other applications that simulate user input) most probably uses the SendInput API:

SendInput operates at the bottom level of the input stack. It is just a backdoor into the same input mechanism that the keyboard and mouse drivers use to tell the window manager that the user has generated input.
Source: http://blogs.msdn.com/b/oldnewthing/archive/2010/12/21/10107494.aspx

So there is probably no way to tell whether the input is coming from a "real" keyboard or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文