VB 怎么检测全局 keyup事件
PrivateDeclareFunctionGetAsyncKeyStateLib"user32"(ByValvKeyAsLong)AsIntegerPrivateSub...
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyControl) Then
SendKeys "这就是它的效果"
End If
End Sub
如上面的代码,我按住的时间长了就不停的输出“这就是它的效果”有没有办法检测到放开热键时再输出“这就是它的效果”或都用其它别的什么方法让字符只输出一次,下次再按热件时再只输出一次呢?? 展开
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyControl) Then
SendKeys "这就是它的效果"
End If
End Sub
如上面的代码,我按住的时间长了就不停的输出“这就是它的效果”有没有办法检测到放开热键时再输出“这就是它的效果”或都用其它别的什么方法让字符只输出一次,下次再按热件时再只输出一次呢?? 展开
2个回答
展开全部
'声明个布尔型变量,用来标记是否已输出
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static f As Boolean
If GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyControl) Then
If Not f Then '判断是否已输出
SendKeys "这就是它的效果"
f = True '标记输出
End If
Else
f = False '松开按键后复位标记变量
End If
End Sub
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static f As Boolean
If GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyControl) Then
If Not f Then '判断是否已输出
SendKeys "这就是它的效果"
f = True '标记输出
End If
Else
f = False '松开按键后复位标记变量
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询