Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 689
Andro Miguel M. Bondoc Avatar asked Feb 17 '11 03:02

Andro Miguel M. Bondoc


2 Answers

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

like image 152
OJ. Avatar answered Oct 24 '22 09:10

OJ.


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.

like image 9
casablanca Avatar answered Oct 24 '22 09:10

casablanca