简体   繁体   English

如何使用Winforms创建自定义热键

[英]how do I create custom hotkey using winforms

I had been asked to create winform application where there are two comboboxes. 我被要求创建有两个组合框的winform应用程序。
The first box contains options like Ctrl+Alt , Ctrl+Shift and Alt+Shift . 第一个框包含Ctrl + AltCtrl + ShiftAlt + Shift之类的选项 The second box contains alphabets from az and numbers 0-9 .. 第二个框包含az字母和数字0-9 ..
The form also contains a button called "Register". 该表单还包含一个名为“注册”的按钮。 My task is that, when I click the register button, the options selected in the combo boxes must be considered as the hotkey and it should be registered. 我的任务是,当我单击注册按钮时,在组合框中选择的选项必须被视为热键,并且应该对其进行注册。 Kindly help me with the code, as I am new to this technology. 由于我是这项技术的新手,请帮助我编写代码。

private void button1_Click(object sender, EventArgs e)
{
    if (comboBox1.SelectedItem.ToString() != str && comboBox3.SelectedItem.ToString() != s)
    {
        str = comboBox1.SelectedItem.ToString();
        byte str1 = (byte)(str)[0];
        s = comboBox3.SelectedItem.ToString();
        byte s1 = (byte)(s)[0];
        RegisterHotKey(this.Handle, this.GetType().GetHashCode(), Win32Modifiers, s1);
    }
    base.WndProc(ref msg);
}

protected override void WndProc(ref Message m)
{
    if(m.Msg ==  )
    base.WndProc(ref m);
}

This is what I had did so far 这是我到目前为止所做的

I would go about this by just simulating the keys selected being pressed. 我将仅通过模拟选择的按键来解决这个问题。 like how and auto-typer would. 就像如何和自动打字机一样。 C# Simulate Key Press check this out and see if you could figure it out from there. C#Simulate Key按下此按钮,看看是否可以从那里弄清楚。 good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM