Reputation: 390
Let me see if I can describe what I'm trying to do. Currently, your mouse is limited to only moving from within the bounds of your screen dimensions. I'm wanting to remove this restriction and allow the mouse to continue outside the bounds (theoretically infinite) and have it control aspects within a program I'm building, but then return the mouse back to the screen when it moves back into screen dimensions. So my thoughts were that once the mouse reaches and breaches the edges of the screen, my program would begin to suppress mouse messages (and also keyboard/clipboard messages) from being sent on, but then continue to monitor raw mouse (and keyboard/clipboard) delta changes from that point on until it comes back in screen range.
I've already got a working example that uses SetWindowsHookEx() and returns low level mouse events such as WM_MOUSEMOVE, however, the struct that is returned (MSLLHOOKSTRUCT) doesn't seem to be low level enough for what I'm looking for as this example returns a screen X and Y coordinate, but instead I need something closer to a delta instead of "rendered" coordinates. From the documentation, it would seem that I need RAWMOUSE data instead. There is plenty of documentation about the RAWMOUSE data type but not too much documentation on how you hook into to get that type of message.
As mentioned too, I'm also looking to monitor keyboard and clipboard type events also (to suppress when mouse is off-screen, controlling my program), so if there is a better method that allows for those to be properly hooked into to monitor/suppress, but it sounds like I don't necessarily need the keyboard and clipboard events to be raw data as there's no bounds that the keyboard and clipboard can breach like the mouse can. But I'd consider keyboard/clipboard suppression to be out of the scope of my current problem, but helpful if the solution happens to solve that problem also.
Upvotes: 1
Views: 2708
Reputation: 595497
There is plenty of documentation about the RAWMOUSE data type but not too much documentation on how you hook into to get that type of message.
You need to use RegisterRawInputDevices()
to register the mouse, and then you need to handle the WM_INPUT
window message to get the movement data. See Raw Input on MSDN for more details.
Note, however, that you can use the RawInput API to only observe the mouse activity, but you cannot block it with that API. You need to continue using SetWindowsHookEx()
for that. So your hooks will need to coordinate with each other. See Combining Raw Input and keyboard Hook to selectively block input from multiple keyboards on CodeProject to get an idea of how to do that (using mouse hooks instead of keyboard hooks).
I'm also looking to monitor keyboard and clipboard type events also (to suppress when mouse is off-screen, controlling my program)
You can use the RawInput API to observe keyboard activity as well, just not block it. Use SetWindowsHookEx()
for that.
As for clipboard events, you need to use AddClipboardFormatListener()
(Vista and later), or SetClipboardViewer()
(XP and earlier) for that. See Monitoring Clipboard Contents on MSDN for more details.
However, this only allows you to detect when changes occur to the clipboard, but there is no API way to block clipboard changes (you would have to directly hook the SetClipboardData()
and OleSetClipboard()
functions in every running process).
Upvotes: 1