1

When I have found a certain Process, is there any way to listen for all keypresses made when the process window is in focus?

I know that I can register a global key listener. But is there any way to use it only when my process window is "active"/in focus? Or even better; is there a way to capture keys from my process only?

foreach (Process clsProcess in Process.GetProcesses()) {

    if (clsProcess.ProcessName.Contains("myProcess"))
    {
        Process theProcess = clsProcess;
    }
}

Global hotkeys implementation: Capture a keyboard keypress in the background

Community
  • 1
  • 1
Johan
  • 35,120
  • 54
  • 178
  • 293

1 Answers1

0

In your keyboard hook, check to see if the handle returned by the GetForegroundWindow() API matches that of the MainWindowHandle() property in the Process you are interested in...

Idle_Mind
  • 38,363
  • 3
  • 29
  • 40