C# 为程序设置全局热键/Hotkey

C# 为程序设置全局热键/Hotkey

首先我们需要定义一个Hotkey(热键)类,我推荐大家通过新建一个类文件来存放代码,方便以后调用,例如我的类文件代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Collections;

namespace Windows
{
public delegate void HotkeyEventHandler(int HotKeyID);

public class Hotkey : System.Windows.Forms.IMessageFilter
{
    Hashtable keyIDs = new Hashtable();
    IntPtr hWnd;
     
    static public int Hotkey1;

    public event HotkeyEventHandler OnHotkey;

    public enum KeyFlags
    {  
        MOD_NONE= 0x0,
        MOD_ALT = 0x1,
        MOD_CONTROL = 0x2,
        MOD_SHIFT = 0x4,
        MOD_WIN = 0x8
    }
    [DllImport(&#

你可能感兴趣的:(c#,runtime)