0

Is it possible to check pressed keys in a Console Application in any other way than Console.ReadKey()?

I've changed the project settings to Windows Application so that the console window won't show. But if the console window isn't shown the application crashes since Console.ReadKey() requires a console window. Is there any workaround?

NOTE: I don't want any window open, just track a key-press, through a thread.

Chris Mantle
  • 6,595
  • 3
  • 34
  • 48
  • 2
    You want to capture keypress even if your program is minimized, in that case you have to go to low level windows api programming – Carlos487 Feb 05 '15 at 14:49
  • When I want an executable with no UI, my standard is to use WinForms and not show a form, rather than a Console application and not show the console. – SimpleVar Feb 05 '15 at 14:53

1 Answers1

-5

You cannot receive key pressed event if you do not have a window. You hae to have a console or "desktop" window.

In case of console 'Console.ReadKey()' does the job, in case of WPF or Windows Forms 'KeyPressed' event does the job.

TIKSN
  • 615
  • 1
  • 6
  • 24
  • Except you very much can. There are many ways to listen to global keyboard events, regardless to whether you have or don't have a window. – SimpleVar Feb 05 '15 at 14:54
  • It is hotkeys, they are not pressed "in your application" – TIKSN Feb 05 '15 at 14:55
  • There are HotKeys, which are OS-managed, and usable by the appropriate Windows API. There are also global hooks, which are not HotKeys, but simply "global key events" listeners. Also, the requirements of the OP is not to capture keys that are pressed "in your application", but to capture keys that are pressed (if OP doesn't have a window in the first place, it's pretty obvious that he means globally). – SimpleVar Feb 05 '15 at 14:56