Vb.net注册一个带有异步状态函数的CTRL组合



我正在尝试制作一个完全由键盘控制的计算器。

我在注册键盘上的按键时遇到了一些麻烦,但最终我使用了GetAsyncKeystate函数

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
For i = 1 To 255
result = 0
result = GetAsyncKeyState(i)
If result = -32767 Then
Select Case i
Case Is = 96
Display.Text = Display.Text & "0"
ans = ans & "0"
Case Is = 97
Display.Text = Display.Text & "1"
ans = ans & "1"
Case Is = 98
Display.Text = Display.Text & "2"
ans = ans & "2"
Case Is = 99
Display.Text = Display.Text & "3"
ans = ans & "3"
Case Is = 100
Display.Text = Display.Text & "4"
ans = ans & "4"
Case Is = 101
Display.Text = Display.Text & "5"
ans = ans & "5"
Case Is = 102
Display.Text = Display.Text & "6"
ans = ans & "6"
Case Is = 103
Display.Text = Display.Text & "7"
ans = ans & "7"
Case Is = 104
Display.Text = Display.Text & "8"
ans = ans & "8"
Case Is = 105
Display.Text = Display.Text & "9"
ans = ans & "9"
Case Is = 106
Multiply()
Case Is = 107
Add()
Case Is = 110
Display.Text = Display.Text & ","
ans = ans & ","
Case Is = 109
Substract()
Case Is = 111
Devide()
Case Is = 13 And ActionValue <> ""
Action()
Display.Text = ans2
Display.Text = Display.Text & Environment.NewLine
ans = ans2
ans2 = ""
End Select
End If
Next i
End Sub

现在我不知道该如何注册Ctrl组合(如Ctrl+NUM-LOCK)顺便说一句,我不习惯GetsAsyncKeyState函数

您首先需要检查是否在开始时按下了CTRL键或任何其他修改键,如Alt或其他任何键。(参见http://msdn.microsoft.com/en-us/library/dd375731%28VS.85%29.aspx用于键代码)。定义变量,如

Dim isCTRLPressed as Boolean = (GetAsyncKeyState(&HA2) < 0)

当处理实际的密钥时,您可以分叉相应的动作

If isCTRLPressed Then
DoThis()
Else
DoThat()
End If

如果你的意思是其他的,你可以在你的帖子中详细说明。您的代码也相当低效,因为无论是否实际使用,您都要强制检查每个Tick上的每个keystate。

最新更新