3

Possible Duplicate:
Global keyboard capture in C# application

Hi all,

I am making a .NET application (Window Forms) which is written by C# and I get a problem. How to hide my personal .NET application using a keyboard shortcut and then displaying it back from same keyboard shortcut.

Thanks !

4

1 Answer 1

1

First you should probably clarify which technology you're using: WinForms, WPF?

Anyway, using WinForms You can use the KeyDown event to process such occurrences:

private void OnKeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
     if (e.Shift && e.KeyCode == Keys.M) 
     {
         WindowState = FormWindowState.Minimized;
     }        
}

Note that the modifier key/s and regular key/s you require to be pressed to carry out the action are obviously changeable.

A further note is that once this action has been executed then the window no longer has 'focus' and so repeating the keystrokes to display the window again will not work - for this to happen you will need to register a hot-key that Windows itself knows about or use a keyboard hook to intercept keystroke input to the system to consume in your application, AFAIK.

2
  • This is correct. Additionally you can register a KeyPress event for your form (I assume that your application will be in Windows Forms), that will invert each time the Visible property of your form. To show up your application with the same key, make sure that it is selected at the task bar (otherwise the keystroke will not raise the form's event).
    – nantito
    Apr 28, 2011 at 14:54
  • 3
    Only problem here is he wants to then show the program again with the same key, which would require a system wide hook. This particular example only really solves half the problem Apr 28, 2011 at 14:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.