用GetAsyncKeyState实现隐藏与重现的问题
我想用GetAsyncKeyState仅用一个键来实现窗体的隐藏与重现,比如下面代码就用"0"来实现
Option Explicit
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Private Function MyHotKey(vKeyCode) As Boolean ' 声明的自定义函数
MyHotKey = GetAsyncKeyState(vKeyCode) < 0 '结果的高位指出该键当前是否被按下(是为1,否为0)故按下为负,未按为0
End Function
Private Sub Timer1_Timer()
Static a As Boolean
If (MyHotKey(vbKey0) And (Not a)) Then '第一次按下,隐藏.
Me.Hide
a = True
End If
If (MyHotKey(vbKey0) And a) Then '第二次按下,重现.
Me.Show
a = False
End If
End Sub
不过不知怎么回事竟然实现不了,哪位高手帮忙解释下,顺便给个可以用一个键实现隐藏与重现的方法,谢谢了~~
[解决办法]
‘优化’一下:
Option ExplicitPrivate Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As IntegerPrivate Function MyHotKey(vKeyCodeas As Long) As Boolean MyHotKey = GetAsyncKeyState(vKeyCodeas) < 0End FunctionPrivate Sub Timer1_Timer() Static a As Boolean If (MyHotKey(vbKey0)) Then Me.Visible = a: a = Not a While (MyHotKey(vbKey0)) DoEvents Wend End IfEnd Sub