Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Low level keyboard input from Windows

What win32 calls can be used to detect key press events globally (not just for 1 window, I'd like to get a message EVERY time a key is pressed), from a windows service?

like image 887
dicroce Avatar asked Nov 21 '08 23:11

dicroce


People also ask

What is a keyboard hook?

A hook is a mechanism by which an application can intercept events, such as messages, mouse actions, and keystrokes. A function that intercepts a particular type of event is known as a hook procedure.

What is Wm_syskeydown?

WM_SYSKEYDOWN simulates system commands like ALT + TAB used to switch windows. WM_CHAR simulates user input like input in a text box for instance. WM_KEYDOWN is usually used together with WM_KEYUP . See WM_KEYDOWN message (Windows). Most probably you will want to use WM_CHAR .

What extended key 1?

An extended key is a private key or public key that you can use to derive new keys in a hierarchical deterministic wallet. Therefore, you can have a single extended private key , and use it as the source for all the child private keys and public keys in your wallet.

What type of message is generated by keyboard?

The keystroke messages are WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, and WM_SYSKEYUP. A typical window procedure ignores all keystroke messages except WM_KEYDOWN. The system posts the WM_KEYDOWN message when the user presses a key.


1 Answers

You want to use Win32 Hooks. In particular a keyboard hook.

You can read more about it here

The type of hook you want is WH_KEYBOARD and you can set it via the Win32 API SetWindowsHookEx.

Basically windows will call a function in a dll that you create everytime a key is pressed in any application system wide.

The hook will call your function which will have this interface:

LRESULT CALLBACK KeyboardProc(      
    int code,
    WPARAM wParam,
    LPARAM lParam
);

More information about this callback here.

With windows hooks you can not only track system wide events across all processes, but you can also filter them and stop them altogether.

like image 100
Brian R. Bondy Avatar answered Sep 21 '22 08:09

Brian R. Bondy