如何在系统级别触摸任何输入设备时如何触发按键或鼠标点击事件? [英] How can I fire a key press or mouse click event without touching any input device at system level?
问题描述
这取决于你想要的东西。您要将密钥发送到
- 您的应用
- 另一个固定应用
- 模拟全局按键
全局模拟键
所有这些都将导致针对特定应用程序的问题,活动窗口更改。
-
SendKeys
发送消息到活动的应用程序。这是一个高级功能,采用一个编码一系列密钥的字符串。 -
keybd_event
是非常低的级别,并注入全球按键。在大多数情况下,SendKeys
更容易使用。 -
mouse_event
模拟鼠标输入。 -
SendInput
取代了这些功能。
发送到特定窗口
当使用固定的目标窗口时,发送邮件可以根据窗口的工作原理工作。但由于此不更新所有状态它可能不总是奏效但是,您不需要改变窗口焦点,这是值得的。
-
WM_CHAR
在基本的多语言平面(16位)中发送一个字符 -
WM_UNICHAR
发送支持整个unicode范围的字符 -
WM_KEYDOWN
和WM_KEYUP
通过键盘布局发送将被翻译成字符的键。 - your Application
- another fixed Application
- Simulate a global keypress
SendKeys
Sends Messages to the active app. It's a high level function taking a string which encodes a sequence of keys.keybd_event
is very low level and injects a global keypress. In most casesSendKeys
is easier to use.mouse_event
simulates mouse input.SendInput
supersedes these functions. It's more flexible but a bit harder to use.WM_CHAR
sends a character in the basic multilingual plane (16 bit)WM_UNICHAR
sends a character supporting the whole unicode rangeWM_KEYDOWN
andWM_KEYUP
Sends keys which will be translated to characters by the keyboard layout.
我的建议是指向特定的窗口/应用程序时首先尝试使用消息,并且只有在失败时尝试使用较低级别的解决方案。
How can I fire an automatic key press or mouse click event when a color appears on the screen on other application or browser?
It depends a lot on what you want. Do you want to send the keys to
Simulating keys globally
All of these will cause problems targeting a specific application and the active window changes.
Sending to a specific window
When working with a fixed target window, sending it messages can work depending on how the window works. But since this doesn't update all states it might not always work. But you don't have a race condition with changing window focus, which is worth a lot.
My recommendation is when targeting a specific window/application try using messages first, and only if that fails try one of the lower level solutions.
这篇关于如何在系统级别触摸任何输入设备时如何触发按键或鼠标点击事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!