2

i wrote a console app in c# that listens for specific keypresses on the keyboard and executes code afterwards. Everything works fine as long as the program is the active program.

But I want the program to run also when I "tabbed" out of it.

In other words: When I'm playing a computer game and I press F1, I want the code of my program to be executed.

Is there an easy way to implement it? Is it even possible with console applications?

Thanks in advance :)

Kirk Woll
  • 76,112
  • 22
  • 180
  • 195
Kalle
  • 21
  • 3
  • 2
    The only way I know of is through global keyboard hooks as [described here](https://stackoverflow.com/questions/604410/global-keyboard-capture-in-c-sharp-application). Not sure how easy it is to get working in a console application. – Kirk Woll May 29 '22 at 16:38
  • 1
    You need a global keyboard hook, and for that to work you need to run a [message pump](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.application.run?view=windowsdesktop-6.0#system-windows-forms-application-run) – Charlieface May 29 '22 at 17:01

0 Answers0