Listening to keyboard events in C#

RobertPitt picture RobertPitt · Mar 29, 2011 · Viewed 9.4k times · Source

Im building a small application for my employer where hitting a certain keystroke will display a model box containing information that one of our technicians would require when providing one to one support.

its a very simple application but tracking the keyboard events without causing any issues for the user is puzzling me.

Basically I need to write a class that I can rely on to send me an event when CTRLALT + H are fired.

what's the best methods of completing this without having tons of events fired through my application, for example, ask windows to inform me when the keystroke has been entered.

Regards.

Answer

Daniel Hilgarth picture Daniel Hilgarth · Mar 29, 2011

Use a global hotkey. The link contains a class that encapsulates the P/Invoke stuff required to use global hotkeys in .NET.