Converting [SHIFT] + [NUM] to punctuation mark

I'm using SetWindowsHookEx and WH_KEYBOARD_LL to capture keyboard input.

I have my code running fine, and it's able to capture alphanumeric characters, and punctuation. But, I can't seem to find any solutions for capture [SHIFT] + 1 ... which on a UK keyboard produces an exclamation mark.

I am using GetKeyState to check if [SHIFT] has been pressed. I use towupper to convert the lowercase to uppercase, and this works fine.

But, again I can't figure out how to capture the punctuation on the number keys (top row number keys). The only solution I can find is by hard coding the punctuation so if pressed, it will produce the exclamation mark.

But, this doesn't deal with non UK keyboards where the punctuation will be different.

I am using WM_KEYDOWN as I need to capture keyboard input globally. I have looked at WM_CHAR but it seems that will not work globally.

Any ideas on how to go about this?
Not to worry, solved it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
BYTE keyState[256] = {0};
bool keyStateResult = GetKeyboardState(keyState);
PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;
wchar_t buffer[5];

int toUnicodeResult = ToUnicodeEx(
    p->vkCode,
    p->scanCode,
    keyState,
    buffer,
    _countof(buffer),
    0,
    NULL
);
Last edited on
Topic archived. No new replies allowed.