有一个 RichTextBox,如果用户输入任何键,它将显示在那里。我为“。”尝试了 GetAsyncKeyState。和“-”等但它不起作用但是 AZ 和 0-9 正常工作。
Private Sub tmrKeys_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrKeys.Tick
Dim result As Integer
Dim key As String = Nothing
Dim p As Boolean = CBool(GetAsyncKeyState(Keys.P))
Dim i As Integer
Dim dec As Boolean = CBool(GetAsyncKeyState(Keys.Decimal))
Dim subtract As Boolean = CBool(GetAsyncKeyState(Keys.Subtract))
Dim add As Boolean = CBool(GetAsyncKeyState(Keys.Add))
Try
For i = 2 To 90
result = 0
result = GetAsyncKeyState(i)
If result = -32767 Then
key = Chr(i)
If i = 13 Then key = vbNewLine
Exit For
End If
Next i
If key <> Nothing Then
If My.Computer.Keyboard.ShiftKeyDown OrElse My.Computer.Keyboard.CapsLock Then
txtlogs.Text &= key.ToUpper
ElseIf key = vbBack Then
If txtlogs.TextLength > 0 Then
txtlogs.Text = txtlogs.Text.Remove(txtlogs.TextLength - 1)
End If
ElseIf My.Computer.Keyboard.CtrlKeyDown Then
txtlogs.Text &= " -[CTRL+" & key & "]"
ElseIf subtract = True Then
txtlogs.Text &= "-"
ElseIf My.Computer.Keyboard.ShiftKeyDown AndAlso subtract = True Then
txtlogs.Text &= "_"
ElseIf dec = True Then
txtlogs.Text &= "."
Else
txtlogs.Text &= key.ToLower
End If
End If
我想当用户在键盘 RichTextBox 中按小数点时显示添加“。” 到文字等等
感谢您提前提供任何帮助