How to detect KeyPress while program is running in background in Win32 C++
Asked Answered
M

2

8

I got a program that whenever I minimize it, it goes to the system tray.

i want to know is this: a) how could i detect a key press while my program is in the system tray. b) how could I know what they press in the keyboard specifically the function buttons.

Mehalek answered 17/2, 2011 at 3:43 Comment(0)
M
16

You need to set up a keyboard hook using SetWindowsHookEx(). Look at the WH_KEYBOARD and WH_KEYBOARD_LL hooks.

Mentality answered 17/2, 2011 at 3:52 Comment(3)
Wow, this was voted down! I'm not bitter, just keen to know the reason why :)Mentality
Alternatively, you can use Raw Input to get WM_INPUT messages directly from the keyboard driver. Look at RegisterRawInputDevices().Signatory
after setting up the hook what's next?Twitter
N
10

If you know exactly what keystroke you're expecting, you can use RegisterHotkey and Windows will send you a message when that key is pressed.

If you want to detect all keystrokes, @OJ's answer will work.

Nocturn answered 17/2, 2011 at 4:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.