首页 > 代码库 > VB检测按键CTRL+C的次数

VB检测按键CTRL+C的次数

技术分享

 

 

Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Public chongfu As Integer

Private Sub Timer1_Timer()
Timer1.Interval = 50
X = GetKeyState(vbKeyC)
y = GetKeyState(vbKeyControl)
‘ X = GetAsyncKeyState(vbKeyC)
‘ y = GetAsyncKeyState(vbKeyControl)
Cls
If X < 0 Then
Print "按住了c " & X
Else
Print "没按住c " & X
End If

If y < 0 Then
Print "按住了ctrl " & y
Else
Print "没按住ctrl " & y
End If

If X < 0 And y < 0 And chongfu = 0 Then ‘当ctrl+c按下并且重复次数为0,caption加个C
Me.Caption = Me.Caption & "C"
chongfu = 1 ‘加个C之后,把重复次数变成1,表示重复多次
ElseIf X >= 0 Then ‘如果C键弹起就把重复次数清零
chongfu = 0
End If
End Sub

 

VB检测按键CTRL+C的次数