1.VB后台按键
VB后台按键
我有啊!后台
为程序注册热键
方法一:修改注册表
Private Declare Function RegisterHotKey Lib "user" (ByVal hWnd As Long,按键s按asp 新闻 源码 ByVal id _
As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Private Declare Function UnregisterHotKey Lib "user" (ByVal hWnd As Long, ByVal id _
As Long) As Long
Private Declare Function PeekMessage Lib "user" Alias "PeekMessageA" (lpMsg As Msg, _ ByVal hWnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long, ByVal _ wRemoveMsg As Long) As Long
Private Declare Function WaitMessage Lib "user" () As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type Msg
hWnd As Long
Message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
' 声明常数
Private Const MOD_ALT = &H1
Private Const MOD_CONTROL = &H2
Private Const MOD_SHIFT = &H4
Private Const PM_REMOVE = &H1
Private Const WM_HOTKEY = &H
Private HotKey_Fg As Boolean
Private Sub Form_Load()
Dim Message As Msg
'注册 Ctrl+Y 为热键
RegisterHotKey Me.hWnd, &HBFFF&, MOD_CONTROL, vbKeyY
'RegisterHotKey Me.hWnd, &HBFF2&, MOD_CONTROL, vbKeyU 为ctrl+U
'把MOD_CONTROL改为0 ,vbkeyY改为F1就试试
Me.Show
Form1.Hide
'等待处理消息
HotKey_Fg = False
Do While Not HotKey_Fg
'等待消息
WaitMessage
'检查是源码120的源码否热键被按下
If PeekMessage(Message, Me.hWnd, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
Form1.Show '这里是处理过程
End If
'转让控制权,允许操作系统处理其他事件
DoEvents
Loop
End Sub
Private Sub Form_Unload(Cancel As Integer)
HotKey_Fg = True
'撤销热键的注册
Call UnregisterHotKey(Me.hWnd, &HBFFF&)
End Sub
方法二:SendMessage
Private Declare Function SendMessage Lib "user" Alias "SendMessageA" (ByVal hwnd As _ Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SETHOTKEY = &H
Private Const HOTKEYF_SHIFT = &H1
Private Const HOTKEYF_ALT = &H4
Private Sub Form_Load()
Dim l As Long
Dim wHotkey As Long
wHotkey = (HOTKEYF_ALT) * (2 ^ 8) + '定义ALT+A为热键
l = SendMessage(Me.hwnd, WM_SETHOTKEY, wHotkey, 0)
End Sub