hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, hInstance, 0);
The KeyboardProc() function is a callback function that is called by the OS every time a key is pressed. Inside KeyboardProc(), you decide if you want to trap the key or let the OS (or the next application in the hook chain) process it:LRESULT KeyboardProc(...) { if (Key == VK_SOMEKEY) return 1; // Trap key return CallNextHookEx(...); // Let the OS handle it }To release the hook, you use:
UnhookWindowsHookEx(hKeyboardHook);There are two type of hooks: local and global (or system wide) hooks. Local hooks can only trap events for your application, while global hooks can trap events for all the running applications.