添加快捷鍵
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要VBAPI函數:
GetAsyncKeyState←判斷函數調用時指定虛擬鍵的狀態
--------------------------------------------------------------------------------------------------------------------------------------------------------
相關API聲明:
GetAsyncKeyState
↓
PrivateDeclareFunctionGetAsyncKeyStateLib"user32"(ByValvkeyAsLong)AsInteger
PrivateFunctionMyHotKey(vKeyCode)AsBoolean
--------------------------------------------------------------------------------------------------------------------------------------------------------
需要的控件:Timer(interval不為空)
--------------------------------------------------------------------------------------------------------------------------------------------------------
代碼:
PrivateDeclareFunctionGetAsyncKeyStateLib"user32"(ByValvkeyAsLong)AsInteger
PrivateFunctionMyHotKey(vKeyCode)AsBoolean
MyHotKey=(GetAsyncKeyState(vKeyCode)<0)
EndFunction
'然後在循環中或Timer的Timer事件中檢測:
PrivateSubTimer1_Timer()
IfMyHotKey(vbKeyA)AndvbKeyControlThen'ctrl A
End'關閉
EndIf
'其中vbkeyA是鍵盤″A″的常數,其他鍵可按F1查得。
EndSub
--------------------------------------------------------------------------------------------------------------------------------------------------------
其它方法:
比如按下"ctrl A"就退出!
'可以設置Form的KeyPreview屬性為True,然後在Form_KeyDown事件中添加代碼:
PrivateSubForm_KeyDown(KeyCodeAsInteger,ShiftAsInteger)
IfKeyCode=Asc("A")AndShift=vbCtrlMaskThenunloadme'如果ctrl A鍵被按下就退出
EndSub
->