[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 }
1.首先引入System.Runtime.InteropServices using System.Runtime.InteropServices; 2.在类内部声明两个API函数,它们的位置和类的成员变量等同.[System.Runtime.InteropServices.DllImport("user32.dll")] //申明API函数 public stati