参考一下文档里的例子- #https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-registerhotkey
-
- Add-Type @"
- using System;
- using System.Runtime.InteropServices;
-
- public class HotKey
- {
- [DllImport("user32.dll")]
- public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
- [DllImport("user32.dll")]
- public static extern bool GetMessage(uint[] lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
- }
- "@
-
- if ([HotKey]::RegisterHotKey(
- 0,
- 1,
- 1 + 0x4000,
- 0x42)) #0x42 is 'b'
- {
- "Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"
- }
-
- $msg = new-object int[] 7
- while ([HotKey]::GetMessage($msg, 0, 0, 0) -ne 0)
- {
- if ($msg[2] -eq 0x0312)
- {
- "WM_HOTKEY received\n"
- }
- }
复制代码
|