https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-sethotkey

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerhotkey

https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-unregisterhotkey

https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes

WM_SETHOTKEY


[DllImport("user32.dll")]
static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

IntPtr maindHwnd = FindWindow(null, "C-Media Audio Control Panel");            
SendMessage(maindHwnd, 0x32, IntPtr.Zero, IntPtr.Zero);

RegisterHotKey

[DllImport("user32.dll", SetLastError = true)]
static extern bool UnregisterHotKey(IntPtr hWnd, int id);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);

bool isKeyRegisterd = RegisterHotKey(Handle, ID, Modifiers, Key);
UnregisterHotKey(Handle, ID);
分类: articles