【问题标题】:Multiple questions for Visual BasicVisual Basic 的多个问题
【发布时间】:2012-12-17 00:27:22
【问题描述】:

如何在 Visual Basic Express 中执行以下操作?

a) 使用程序按键盘上的“delete”、“home”和“shift”。 // 仍然需要弄清楚如何做到这一点。
b) 检测何时按下“z”和“x”。 // 我现在使用的是按钮而不是这部分。

非常感谢! :)

  • Windows 窗体应用程序

【问题讨论】:

  • 这是WEB表单、WIN表单、MVC、ETC???
  • Windows 窗体应用程序

标签: vb.net winforms


【解决方案1】:

这是“一种”方式.. 它检测到 .NET Win Forms 中的 Enter 按下。 13 代表“输入”。

   Public Function KeyAscii(ByVal UserKeyArgument As KeyPressEventArgs) As Short
        KeyAscii = Asc(UserKeyArgument.KeyChar)
    End Function

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If KeyAscii(e) = 13 Then
            MsgBox("you press ENTER key")
        End If
    End Sub

通过使用类似的方法来检测您的按键,可以找到更多的按键类型。

Private Sub Form_KeyPress(KeyAscii As Integer)
    Debug.Print "KeyAscii: " & KeyAscii
End Sub

Private Sub Form_Load()
    Form1.KeyPreview = True
End Sub 

【讨论】:

    【解决方案2】:

    我认为 SendKey 功能会满足您的需求。

    【讨论】:

      【解决方案3】:

      a) 要发送键盘命令,您可以使用 SendKeys 方法。
      b) 要捕获击键,请查看support article.

      【讨论】:

        猜你喜欢
        • 2011-02-25
        • 2011-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多