In my hook procedure (for keyboard) when I click right alt it sends me two codes on press and two on release:
The code:
LRESULT CALLBACK Recorder::keyboardHookProcedure( int code, WPARAM wParam, LPARAM lParam ) {
if( code < 0 )
return CallNextHookEx( m_mouseHook, code, wParam, lParam );
DWORD _vkCode = reinterpret_cast<KBDLLHOOKSTRUCT*>( lParam )->vkCode;
qDebug( "vkCode: %d, wparam: %d, lparam: %d", _vkCode, wParam, lParam );
return CallNextHookEx( 0, code, wParam, lParam );
}
on pressing
vkCode: 162, wparam: 260, lparam: 3398032
vkCode: 165, wparam: 260, lparam: 3398032
on releasing
vkCode: 162, wparam: 257, lparam: 3398032
vkCode: 165, wparam: 257, lparam: 3398032
moreover, notice that when you press the key it sends it as WM_SYSKEYDOWN (260), but when you release it the wParam is WM_KEYUP (257). What the…? Why does it work in such way?
It’s because the right alt-key (ALT-GR) is a shortcut for two keys – ALT and CTRL
You get WM_SYSKEYDOWN but WM_KEYUP because that’s how the messages are defined – if you’re expecting WM_SYSKEYUP, you get that when you release a key that is pressed in conjunction with the ALT key – http://msdn.microsoft.com/en-us/library/windows/desktop/ms646287(v=vs.85).aspx