The other day I decided to learn keyboard hooks because I was working on a small project to read key inputs. After some brainstorming and losing my mind, I came up with this.

Hook program
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (nCode == HC_ACTION && wParam == WM_KEYDOWN) {
KBDLLHOOKSTRUCT *kb = (KBDLLHOOKSTRUCT*)lParam;

unsigned char keyboard_state[256];
wchar_t unicodeData[5] = {0};
GetKeyboardState(keyboard_state);

int unicodeKey = ToUnicodeEx(kb->vkCode, kb->scanCode, keyboard_state,
unicodeData, sizeof(unicodeData) / sizeof(wchar_t),
0, NULL);

if (unicodeKey > 0) {
printf("%ls", unicodeData);
}

if (kb->vkCode == VK_RETURN) {
printf("\n");
}
}
return CallNextHookEx(hook, nCode, wParam, lParam);
}

int main() {
hook = SetWindowsHookEx(WH_K...

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help