1. You can put a global hook (needs to be implemented in a dll, in exe global work), check hook this dll will vgryztsya in all processes of the desktop.
2. To look in the direction of the RIT (Raw Input Thread
). In practice, never tried it.
3. Find or write a keyboard filter driver (which is much harder). Unlike the first 2 options, working in user mode, will run in kernel mode.