0

in a C# winform, I have an app that has a 'silent mode' in it, in that mode it gets minimized and hidden from the task bar, AKA:

this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;

But at a certain point, I want the main window of the program to show up again by pressing a certain key combo on the keyboard, like for example Alt+Ctrl+Shift+S But i just don't know how to do that.

The way i got around this was totally different, if the user wanna gets the window back, he'd have to create a file called 'SilentMode.OFF' in a specific directory. doing so will get the window back. I managed to do this by a timer in my app, the timer checks to see if that file is created in that dir, if so, show the window. Not that's not really a pro way to do things.

My Q: how can I communicate with a minimized window ? how can i send it and make it respond to the keys that i want it to respond to ?

I tried some of the events' like the Leave event and some other, but didn't really work.

Any tips would be of great help, Thank you.

Adi Lester
  • 24,731
  • 12
  • 95
  • 110
vexe
  • 5,433
  • 12
  • 52
  • 81
  • 1
    I think you'll find out how using [this][1] and also [this][2] [1]: http://stackoverflow.com/questions/8734453/detect-keypression-when-minimized-and-trayicon [2]: http://stackoverflow.com/questions/11752254/global-windows-key-press – Mahdi Tahsildari Aug 25 '12 at 13:58

2 Answers2

1

AFAIK there is no .NET-wrapper for the hotkey functions in the winapapi. but you can use RegisterHotkey via pinvoke. Here is a detailed explanation: http://www.codeproject.com/Articles/5914/Simple-steps-to-enable-Hotkey-and-ShortcutInput-us

Arno Nühm
  • 93
  • 1
  • 9
-1

You can make a method like:

[DllImport("user32.dll")]
static extern short GetAsyncKeyState(System.Windows.Forms.Keys vKey); 

private void WaitForHotKeys()
{
       if(GetAsyncKeyState(Keys.Alt) != 0 && GetAsyncKeyState(Keys.Control) != 0 && 
          GetAsyncKeyState(Keys.Shift) != 0 && GetAsyncKeyState(Keys.S) != 0)
       {
          this.WindowState = FormWindowState.Normal;
          this.ShowInTaskbar = true;
       }       
}

And add in your load method:

Thread myThread = new Thread(new ThreadStart(WaitForHotKeys));
myThread.Start();
Thanatos
  • 1,176
  • 8
  • 18