HotKeyUtils.cs 934 B

1234567891011121314151617181920212223242526
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows.Forms;
  7. namespace Mir2Assistant.Common.Utils;
  8. public class HotKeyUtils
  9. {
  10. [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI
  11. public static extern bool RegisterHotKey( //设置热键
  12. IntPtr hWnd, // 窗口句柄,一般使用Handle属性
  13. int id, // 区别热键的ID号,这个可以随便写,只是用来区分不同热键
  14. uint fsModifiers, // 修正键用户接下哪些键是发生 可能为contol=2, alt=1, shift=4, windows=8或这些键的组合,如果没有的话直接用0
  15. Keys vk // 键
  16. );
  17. [System.Runtime.InteropServices.DllImport("user32.dll")] //导入WinAPI
  18. public static extern bool UnregisterHotKey( //注销热键
  19. IntPtr hWnd, // 窗口句柄
  20. int id // 键标识
  21. );
  22. }