Keyboard hook: change the key code
I did hook the keyboard of some process. Now I need to change the key message sent to the process.
For example: from lowercase to uppercase and opposit开发者_Go百科e.
How can I do this?
Assuming your function prototype is as follows:
LRESULT CALLBACK WndProc( HWND hWnd, UING uMsg, WPARAM wParam, LPARAM lParam )
,
the value of your letter is inside wParam. Assuming pure ASCII keyboard input, then you can use the following:
short newKeyCode = (char)wParam;
if (uMsg == WM_CHAR || uMsg == WM_SYSCHAR)
if (newKeyCode - 'a' < 26) {
newKeyCode = newKeyCode - 'a' + 'A';
} else {
newKeyCode = newKeyCode - 'A' + 'a';
}
Of course, if you're on a Windows system beyond 2000 (and thus running on the NT architecture), wParam will be a Unicode value (and UTF-16, as is the Windows convention), so your program may have to fiddle with this to get it into a nice state, but otherwise this should be all you need.
精彩评论