VB 全局快捷键

PrivateSubForm_KeyDown(KeyCodeAsInteger,ShiftAsInteger)SelectCaseKeyCodeCasevbKeyF12M... Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF12
MsgBox "A"
End Select
End Sub
测试成功后,再加个ShockwaveFlash1控件为什么就用不了了。。。
展开
 我来答
陈学阳
2010-10-16 · TA获得超过2.8万个赞
知道大有可为答主
回答量:2.1万
采纳率:14%
帮助的人:5586万
展开全部
v

呵呵

楼上俩位的,你们那首伏个太占资源了,只有在没有办法的情况下才使用你们这个办法....

使用timer....如果使用这个功能,cup占用可不是一般的多阿~是非常多~

给你这个代码,只搭圆有在按下键盘的时候才会激发~不占资源~~

'模块
Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Private Type PKBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private Const WM_KEYDOWN = &H100
Private Const WM_SYSKEYDOWN = &H104
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYUP = &H105

Private Const HC_ACTION = 0
Private Const WH_KEYBOARD_LL = 13
Private lngHook As Long
Public Function HotKey(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Dim p As PKBDLLHOOKSTRUCT
If nCode = HC_ACTION Then
Select Case wParam
Case WM_KEYDOWN, WM_SYSKEYDOWN
Call CopyMemory(p, ByVal lParam, Len(p))
If p.vkCode = vbKeyF10 Then '这者枝携里定义热键
MsgBox "你按下了F10" '这里,执行你要执行的程序,我这里示范msgbox
End If
Case Else

End Select
End If
Call CallNextHookEx(WH_KEYBOARD_LL, nCode, wParam, lParam)
End Function

Public Sub HooK()
lngHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf HotKey, App.hInstance, 0)
End Sub

Public Sub UnHooK()
Call UnhookWindowsHookEx(lngHook)
End Sub

'窗体
Private Sub Form_Load()
HooK
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHooK
End Sub

如果对您有帮助,请记得采纳为满意答案,谢谢!祝您生活愉快!

vaela
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式