【问题标题】:Detect ANY Key Press and Save检测任何按键并保存
【发布时间】:2017-05-01 17:13:00
【问题描述】:

我知道在 Visual Studio 中您可以检测到特定的按键(例如:Here), 但是有没有办法检测任何键(A-Z, 0-9, Shift, Ctrl, Alt, F1, F2 等)并将其显示为标签(例如:label1)。我打算能够在任何窗口中使用它,而不仅仅是我将制作的 Visual Studio 程序。谢谢!

【问题讨论】:

  • Visual Studio 程序是什么意思,与 C#/Windows 程序相比有何不同?
  • 我编辑了问题!
  • 搜索“低级键盘挂钩”和 WH_KEYBOARD_LL。

标签: c# visual-studio keyboard key detect


【解决方案1】:

根据您的需要制作条件。示例来源Here

void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar >= 48 && e.KeyChar <= 57)
    {
        MessageBox.Show("Form.KeyPress: '" +
            e.KeyChar.ToString() + "' pressed.");

        switch (e.KeyChar)
        {
            case (char)49:
            case (char)52:
            case (char)55:
                MessageBox.Show("Form.KeyPress: '" +
                    e.KeyChar.ToString() + "' consumed.");
                e.Handled = true;
                break;
        }
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-31
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 2014-07-27
    • 2013-12-14
    相关资源
    最近更新 更多