首页 > 解决方案 > 如何添加多个热键?像 f1 f2 f3

问题描述

我不明白: Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
KeyModifier 修饰符 = (KeyModifier)((int)m.LParam & 0xFFFF);

在此代码中只添加一个热键,我如何添加多个热键?喜欢f1 f2 f3。。。。</p>

public partial class Form1 : Form
{
 
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
    [System.Runtime.InteropServices.DllImport("user32.dll")]
    private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

    enum KeyModifier
    {
        None = 0,
        Alt = 1,
        Control = 2,
        Shift = 4,
        WinKey = 8
    }
    public Form1()
    {
        InitializeComponent();
        int id = 0;    

        RegisterHotKey(this.Handle, id, 0, Keys.F2.GetHashCode());
        


    }

 protected override void WndProc(ref Message m)
    {
        base.WndProc(ref m);

        if (m.Msg == 0x0312)
        {
        

            Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);             
            KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);       
            int id = m.WParam.ToInt32();                                       


            MessageBox.Show("Hotkey has been pressed!");
          
        }
    }

标签: c#

解决方案


推荐阅读