如何检查 VB 中按下的键

How to check the key pressed in VB

我正在尝试制作一个需要你 select 热键的程序,但你只能从我生成的代码中给出一个字符,因为我希望能够设置类似F9也是。我已经在这个网站上浏览过一些,这是最接近我想要的。我正在使用 Visual Studio 2013.

这就是我目前所知道的。

Private Sub Configure_KeyPress(sender As Object, e As KeyPressEventArgs) Handles MyBase.KeyPress
    MsgBox("Your new hotkey is: " & e.KeyChar)
End Sub

提前致谢。

KeyPress event is not raised by non-character keys other than space and backspace; however, the non-character keys do raise the KeyDown and KeyUp 事件。

TextBox1ReadOnly 属性 设置为 true 并处理 keyDown 事件:

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox2.KeyDown
    Me.TextBox1.Text = e.KeyData.ToString()
End Sub 

这还会显示文本框中的组合键,例如,如果您按 Ctrl + Shift + F9你会在文本框中看到F9, Shift, Control

您可以使用 KeyCodeModifiersKeyEventArgs 的其他属性来获取有关键的信息。