3

I am looking for something to close my program that is running in the background with a key press (on a keyboard).

I tried playing with the Key Press event, but this only works when the form is selected/active. When you alt tab it doesn't read the keys :/

private void Test_KeyPress(object sender, KeyPressEventArgs e)
{
    g_StopFlag = true;
}

Is there any way for it to fire without form being selected? Any help would be appreciated!

PS: I am using C#

MethodMan
  • 18,625
  • 6
  • 34
  • 52
Drakon
  • 41
  • 3
  • what type of research have you done beside playing..? have you done any google searches there are examples on the web for this – MethodMan Oct 06 '15 at 01:50
  • This should help you : http://stackoverflow.com/questions/604410/global-keyboard-capture-in-c-sharp-application – fahimalizain Oct 06 '15 at 01:52
  • http://www.codeproject.com/Articles/6362/Global-System-Hooks-in-NET – MethodMan Oct 06 '15 at 01:52
  • Assuming this is Windows-you have to set up a global keyboard hook. Start here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644990(v=vs.85).aspx – edtheprogrammerguy Oct 06 '15 at 01:56

0 Answers0