开发者

Keyboard hook: change the key code

开发者 https://www.devze.com 2023-02-21 17:07 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消