There is a third-party process with gui, in which several threads are running. You need to install the keyboard hook on the gui thread of this process. I do as follows:
processID = 8888; //pid HWND hWnd = GetForegroundWindow(); DWORD threadID = GetWindowThreadProcessId(hWnd, &processID); hHook = SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)&KeyboardProc, GetModuleHandle(NULL), threadID); processId manually from the Task Manager (for debugging, then it will be returned by the script). If you replace the threadID parameter in the last line with 0, then the hook works, but it works everywhere - even in the browser. What am I doing wrong?