VB中如何实现键盘控制?

2024-12-15 16:07:26
推荐回答(2个)
回答1:

Private Sub Command2_Click(Index As Integer)
Dim mesflag As Integer
If Not DYFLAG Then
ShowFrmMsg ("xxx")
Exit Sub
End If
Select Case Index
Case 0
cmdflag = True
Case 1
cmdflag = False
End Select
If cmdflag = True And CEResuit = True Then
mesflag = 0
Else
mesflag = -1
End If
SendMES strInspectSN & "," & mesflag
txtFTMES(0).Text = strInspectSN & "," & mesflag
DYFLAG = False
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 49 Then Command2_Click 1
If KeyAscii = 48 Then Command2_Click 0

End Sub

Private Sub Form_Load()
Me.KeyPreview = True

End Sub

回答2:

Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc("0") Then
Call Command2_Click(0)
ElseIf KeyAscii = Asc("1") Then
Call Command2_Click(1)
End If
End Sub

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