在我的钩子程序(用于键盘)中,当我单击右 alt 时,它会在按下时向我发送两个代码,在释放时发送两个代码:
编码:
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 );
}
按下时
vkCode: 162, wparam: 260, lparam: 3398032
vkCode: 165, wparam: 260, lparam: 3398032
在发布时
vkCode: 162, wparam: 257, lparam: 3398032
vkCode: 165, wparam: 257, lparam: 3398032
此外,请注意,当您按下键时,它会将其发送为WM_SYSKEYDOWN (260),但是当您释放它时, wParam 是WM_KEYUP (257)。什么……?为什么它以这种方式工作?