[英]Distinguish between user generated and my own application generated mouse moves
My WinForms app moves the mouse cursor about the form simply by setting the Cursor.Position
property in some kind of a loop with a timer. 我的WinForms应用程序只需在某种形式的带有计时器的循环中设置
Cursor.Position
属性,即可在窗体上移动鼠标光标。
I would like this movement to continue only till the user does not wield the mouse himself to move it. 我希望这种运动能够继续下去,直到用户自己不挥动鼠标来移动它。 As soon as he or she does, I want my code to stop.
只要他或她这样做,我就希望我的代码停止。
Therefore, I need a way to distinguish between mouse moves that the user generated mouse movement sent vs. those that my application generates. 因此,我需要一种方法来区分用户生成的鼠标移动和应用程序生成的鼠标移动 。
If you use the Win32 SendInput API to position the mouse cursor, you can set a custom dwExtraInfo
value in the MOUSEINPUT structure. 如果使用Win32 SendInput API定位鼠标光标,则可以在MOUSEINPUT结构中设置自定义
dwExtraInfo
值。
When processing an asynchronous (posted) message, you can use the Win32 API GetMessageExtraInfo to retrieve the custom value. 处理异步(已发布)消息时,可以使用Win32 API GetMessageExtraInfo检索自定义值。
A straightforward solution for Windows 8 and up: use the GetCurrentInputMessageSource
function. Windows 8及更高版本的直接解决方案:使用
GetCurrentInputMessageSource
函数。
if originId
is IMO_INJECTED
, the input is emulated. 如果
originId
为IMO_INJECTED
,则模拟输入。 Otherwise, it usually equals IMO_HARDWARE
. 否则,它通常等于
IMO_HARDWARE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.