The keybd_event
documentation states that the function should be used for generating keystrokes and not for detecting them:
Synthesizes a keystroke. The system can use such a synthesized keystroke to generate a WM_KEYUP or WM_KEYDOWN message.
The documentation also states that the method is deprecated (which could explain the lack of resources):
Note This function has been superseded. Use SendInput instead.
... It looks as though you need a different function.
To detect a keypress irrespective of whether the window is in focus or not, you have a few options:
- Use the
RegisterHotkey
function to detect the pressing of a hotkey.
- Use the
SetWindowsHookEx
function to hook the keyboard and to receive notifications whenever any key is pressed.
- Use the
GetKeyState
function to poll the state of a key.
Each of these functions have a copious number of tutorials that are only a Google search away.