天天看點

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