I have somewhere in my code a loop function that call PeekMessage
in order to retrieve events.
Currently it looks like this:
while (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
{
// Process events
}
Now I would like to manage input in a different location, meaning I'd like to retrieve messages such as WM_KEYDOWN
, WM_MOUSEMOVE
(mouse and keyboard events) in a different place, at a different time of my main loop.
PeekMessage
's third and fourth arguments allow to define a range of message to return, so I could use this, using provided macros WM_KEYFIRST
, WM_KEYLAST
, WM_MOUSEFIRST
and WM_MOUSELAST
. But it's unconvenient because I have two ranges to check for input, and therefore three ranges for everything remaining.
The last parameter is a flag and I could pass PM_REMOVE | PM_QS_INPUT
for input. But then, what should I pass in the other loop, where I want to get every other messages? There is no PM_QS_EVERYTHING_EXCEPT_INPUT
macro...
What would be the most elegant way to do this?
PeekMessage retrieves messages associated with the window identified by the hWnd parameter or any of its children as specified by the IsChild function, and within the range of message values given by the wMsgFilterMin and wMsgFilterMax parameters.
The main difference between the two functions is that GetMessage does not return until a message matching the filter criteria is placed in the queue, whereas PeekMessage returns immediately regardless of whether a message is in the queue.
You could try to use "Filters". Win32 calls that "hooks", take a look to msdn's SetWindowsHookEx function. you've got the possibility to install a thread specific filter for keyboard and mouse messages. Then you can push messages to a queue of your maintenance and access it manually later on (knowing you can remove the related messages from the public Queue for that thread if you chose to, from the hook, so that only your user-queue will have the messages). though, you could simply also directly push to this use-queue directly from the PeekMessage switch in every case that is of interest for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With