[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数 public static extern bool RegisterHotKey( IntPtr hWnd, // handle to window int id, // hot key identifier uint fsModifiers, // key-modifier options Keys vk // virtual-key code );
[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数 public static extern bool UnregisterHotKey( IntPtr hWnd, // handle to window int id // hot key identifier );
3.定义一个KeyModifiers的枚举,以便出现组合键
public enum KeyModifiers { None = 0, Alt = 1, Control = 2, Shift = 4, Windows = 8 }