I don't have the exact code, but I can give you some pointers. Use Global-wide hooks and the KeyBoardProc Callback. This can track much better than GetAsyncKeyState.