Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WM_KEYDOWN confusion

Tags:

c++

winapi

I'm trying to get my application to do something when CTRL+S is pressed. I'm just not sure how the W and L params work for WM_KEYDOWN. MSDN has something about bit fields which i'm not sure about. How can I detect CTRL and S? Thanks

What do I do if another control aside from hWnd has focus?

like image 323
jmasterx Avatar asked Apr 25 '10 16:04

jmasterx


1 Answers

Well, this is the big list of virtual key codes.

CTRL-S is going to be sent through as 2 WM_KEYDOWN messages - a message when the ctrl key is pressed (VK_LCONTROL or VK_RCONTROL) followed by a 0x53 for the "S" key.

Rather than processing both messages, wait for the key down message for the 'S' press then call GetKeyState using the magic value VK_CONTROL (otheriwse you'd need to test individually for the left AND right control keys) to see if the S was pressed with CTRL held down.

--

Obviously, keyboard messages are sent directly to the window that has focus. To get accelerator combinations to work at the application scope you need to check the messages before dispatching them to the focus window - i.e. in your message pump. See the documentation for TranslateAccelerator.

If you want to handle system wide keypresses, the other answer points to the hot key api.

like image 142
Chris Becke Avatar answered Sep 21 '22 15:09

Chris Becke