VB定义多个全局快捷键

下面是可以,不过不知道怎么改成加辅助键的,不要按F1,F2的,要ALT加什么的,不要去抄别的代码来,就想用这段,因为别的不好做,要很多个快捷键,PublicDeclare... 下面是可以,不过不知道怎么改成加辅助键的,不要按F1,F2的,要ALT加什么的,不要去抄别的代码来,就想用这段,因为别的不好做,要很多 个快捷键,Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long) As Long

Public Const WM_HOTKEY = &H312
Public Const MOD_ALT = &H1
Public Const MOD_CONTROL = &H2
Public Const MOD_SHIFT = &H4
Public Const GWL_WNDPROC = (-4)
Public preWinProc As Long
Public Modifiers As Long, uVirtKey1 As Long, idHotKey As Long

Public Function SetHotKey()
preWinProc = GetWindowLong(Form1.hwnd, GWL_WNDPROC)
SetWindowLong Form1.hwnd, GWL_WNDPROC, AddressOf Keywndproc
RegisterHotKey Form1.hwnd, 1, 0, vbKeyF1 '注册热键
RegisterHotKey Form1.hwnd, 2, 0, vbKeyF3 '注册热键
'这里还可以添加
End Function

Public Function Keywndproc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_HOTKEY Then
Select Case wParam
Case 1
'热键一
case 2
'热键2
End Select
End If
Keywndproc = CallWindowProc(preWinProc, hwnd, Msg, wParam, lParam)
End Function

窗体
Private Sub Form_Load()
SetHotKey
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim ret As Long
'取消Message的截取,而使之又只送往原来的Window Procedure
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
Call UnregisterHotKey(Me.hwnd, uVirtKey)
End Sub
展开
 我来答
hejian511
2012-08-09 · TA获得超过845个赞
知道大有可为答主
回答量:1559
采纳率:0%
帮助的人:1472万
展开全部
RegisterHotKey Form1.hwnd, 2, 0, vbKeyF3 '注册热键

第三个参数是设定Ctrl alt Shift等的,常数为
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4

'注册一个热键CTRL+shitf+Q
Public Declare Function GlobalAddAtom Lib "kernel32" Alias "GlobalAddAtomA" (ByVal lpString As String) As Integer
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fskey_Modifiers As Long, ByVal vk As Long) As Long
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4

Dim n As Long
lhokkeyid = GlobalAddAtom("MyHotkey")
n = RegisterHotKey(Me.hwnd, lHotkeyId, MOD_CONTROL Or MOD_SHIFT, vbKeyQ)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式