Several methods

1. Use GetKeyboardState API
2. Use GetAsyncKeyState API
3. Use a keyboard hook: SetWindowsHookEx API