C#实现全局热键响应,失去焦点情况下响应全局快捷键
1 、引入API注册和注销热键的函数,建立一个类文件,命名为 HotKey.cs ,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; //使用DllImport
using System.Windows.Forms; //使用keys
{
class HotKey
{
[DllImport("user32.dll")]
// 用于注册热键
public static extern bool RegisterHotKey(
IntPtr hWnd, // 要定义热键的窗口的句柄