Reference using System.Runtime.InteropServices first; The namespaces,
Then add the following code in the appropriate location to OK. Note: Form1_Load and form1_formclosed can not be directly copy Oh ~
Copy Code code as follows:
[DllImport ("user32")]
public static extern bool RegisterHotKey (IntPtr hwnd,int id,uint control,keys VK);
Registering the Hotkey API
[DllImport ("user32")]
public static extern bool Unregisterhotkey (INTPTR hWnd, int id);
private void Form1_Load (object sender, EventArgs e)
{
Register hotkey (form handle, Hotkey ID, auxiliary key, real key)
RegisterHotKey (this. Handle, 888, 2, KEYS.A);
}
private void Form1_formclosed (object sender, Formclosedeventargs e)
{
Injection 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 for the window message definition
if (m.wparam.tostring (). Equals ("888"))//If the hot key we registered for
MessageBox.Show ("You pressed CTRL + a");
Break
}
Base. WndProc (ref m);
}
Secondary key Description:
None = 0,
Alt = 1,
Crtl= 2,
Shift = 4,
Windows = 8
If you have more than one auxiliary key, for example, Alt+crtl is 3 to add directly.