[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
参考一下文档里的例子
  1. #https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-registerhotkey
  2. Add-Type @"
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public class HotKey
  6. {
  7.     [DllImport("user32.dll")]
  8.     public static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
  9.     [DllImport("user32.dll")]
  10.     public static extern bool GetMessage(uint[] lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
  11. }
  12. "@
  13. if ([HotKey]::RegisterHotKey(
  14.     0,
  15.     1,
  16.     1 + 0x4000,
  17.     0x42))  #0x42 is 'b'
  18. {
  19.     "Hotkey 'ALT+b' registered, using MOD_NOREPEAT flag\n"
  20. }
  21. $msg = new-object int[] 7
  22. while ([HotKey]::GetMessage($msg, 0, 0, 0) -ne 0)
  23. {
  24.     if ($msg[2] -eq 0x0312)
  25.     {
  26. "WM_HOTKEY received\n"
  27.     }
  28. }
复制代码

TOP

回复 4# czjt1234


确实理解错了
  1. Add-Type -AssemblyName System.Windows.Forms
  2. Add-Type @"
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public class HotKey
  6. {
  7.     [DllImport("user32.dll")]
  8.     public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  9. }
  10. "@
  11. $hwnd=(ps notepad).MainWindowHandle[0]
  12. $size=[System.Windows.Forms.Screen]::PrimaryScreen.WorkingArea.Size
  13. [HotKey]::MoveWindow($hwnd, $size.width/2, 0, $size.width/2, $size.height, $true)
复制代码

TOP

返回列表