简体   繁体   中英

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.

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.

When processing an asynchronous (posted) message, you can use the Win32 API GetMessageExtraInfo to retrieve the custom value.

A straightforward solution for Windows 8 and up: use the GetCurrentInputMessageSource function.

if originId is IMO_INJECTED , the input is emulated. Otherwise, it usually equals IMO_HARDWARE .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM