Using system;
Using system. Collections. Generic;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. text;
Using system. Windows. forms;
Using system. runtime. interopservices;
Namespace datasource
{
Public partial class hotkey: Form
{
[Dllimport ("USER32")]
Public static extern bool registerhotkey (intptr hwnd, int ID, uint control, keys VK );
// Register the hotkey API
[Dllimport ("USER32")]
Public static extern bool unregisterhotkey (intptr hwnd, int ID );
Public hotkey ()
{
Initializecomponent ();
}
Private void hotkey_load (Object sender, eventargs E)
{
// Register the hotkey (Form handle, hotkey ID, secondary key, and real key)
Registerhotkey (this. Handle, 888, 3, keys. B );
}
Private void hotkey_formclosing (Object sender, formclosingeventargs E)
{
// Delete the hotkey (handle, hotkey ID)
Unregisterhotkey (this. Handle, 888 );
}
Protected override void wndproc (ref message m)
{
Switch (M. msg)
{
Case 0x0312: // This is the registered hotkey message defined by the window message.
If (M. wparam. tostring (). Equals ("888") // if it is the hotkey we registered
If (this. Visible = false)
{
This. Visible = true;
}
Else
{
This. Visible = false;
}
Break;
}
Base. wndproc (ref m );
}
// Auxiliary key description:
// None = 0,
// Alt = 1,
// Crtl = 2,
// Shift = 4,
// Windows = 8
}
}