求vb代码一段
按 alt+q 运行app.path&"123.exe"按 alt+a 运行 app.path&"1234.exe"
补充:最好软件不在最前也可以按alt+q运行
追问:如果要用 ctrl 改哪
按 alt+q 运行app.path&"123.exe"按 alt+a 运行 app.path&"1234.exe"
补充:最好软件不在最前也可以按alt+q运行
追问:如果要用 ctrl 改哪
答案:
下面是代码,创建窗口后直接粘贴到里面就好.用的是api 可以自己修改下热键信息
Option Explicit
Private Declare Function WaitMessage Lib "user32" () As Long
Private Declare Function PeekMessage Lib "user32" 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 UnregisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long) As Long
Private Declare Function RegisterHotKey Lib "user32" (ByVal hWnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Const MOD_ALT = 1
Const MOD_CONTROL = 2
Const MOD_SHIFT = 4
Const PM_REMOVE = 1
Const WM_HOTKEY = 786
Const KEY_A = 65
Const KEY_Q = 81
Private Type msg
hWnd As Integer
Message As Integer
wParam As Integer
lParam As Integer
SendTime As Integer
x As Integer
y As Integer
id As Integer
End Type
Dim logo As Boolean
Private Sub Form_Activate()
logo = False
RegisterHotKey Me.hWnd, 0, MOD_ALT, KEY_Q
RegisterHotKey Me.hWnd, 1, MOD_ALT, KEY_A
WaitMsg
End Sub
Sub WaitMsg()
Dim msg As msg
While logo = False
DoEvents
WaitMessage
If PeekMessage(msg, 0, WM_HOTKEY, WM_HOTKEY, PM_REMOVE) Then
If msg.id = KEY_Q Then '这里是Q键
Shell "calc"
ElseIf msg.id = KEY_A Then '这里是A键
Shell "cmd"
End If
End If
Wend
End Sub
Private Sub Form_Unload(Cancel As Integer)
logo = True
UnregisterHotKey Me.hWnd, 0
UnregisterHotKey Me.hWnd, 1
End
End Sub'新建类模版 代码
Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Const NNi = 18 'ALT声明键盘码常量
Public Const NNG = 81 'Q声明键盘码常量
Public Const NNK = 65 'A声明键盘码常量
'我们只写 你我看得懂的代码
'欢迎编程爱好者加入我们的问问团队【収起兲眞滴笑脸】 我们永远是一个团体?'---------------------------------------------------
'窗体代码
Private Sub Form_Load()
Me.Hide '隐藏窗体
App.TaskVisible = False
Form1.Visible = FalseTimer1.Interval = 1
End SubPrivate Sub Timer1_Timer()
If GetAsyncKeyState(NNi) <> 0 And GetAsyncKeyState(NNG) <> 0 Then '判断用户是否同时按下ALT+Q组合快捷键
App.Path& "123.exe" '如果按下就启动123.exe程序
End If
If GetAsyncKeyState(NNi) <> 0 And GetAsyncKeyState(NNK) <> 0 Then '判断用户是否同时按下ALT+A组合快捷键
App.Path& "1234.exe" '如果按下就启动1234.exe程序
End If
End Sub'最后记得画一个时间控件
你直接在窗体里面弄两个按钮一个按钮的caption属性末尾加上(&Q)这几个字符
另一个加上(&A)这几个字符,然后要shell的东西直接放假command的代码里面不就行了。。
'楼主的意思是用热键调用程序吧,这是刚写的一个hook热键,看合不合楼主心.意。
'窗体代码
Private Sub Form_Load()
HookID = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf myhook, App.hInstance, &O0)
MsgBox "按Q键启动'" & App.Path & "\123.exe'" & vbCrLf _
& "按A键启动'" & App.Path & "\1234.exe'" & vbCrLf _
& vbCrLf & " ---By 腾讯客服---", vbOKOnly, "热键"
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx HookID
End Sub
'--------------------------------------------------------------------
'模块代码
Public 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
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Const WH_KEYBOARD_LL = 13
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Type KEYMSGS
vKey As Long
sKey As Long
Flag As Long
time As Long
keyinfo As Long
End Type
Public keyMsg As KEYMSGS
Public HookID As Long
Public Function myhook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
myhook = 0
If code = HC_ACTION Then
CopyMemory keyMsg, lParam, LenB(keyMsg)
If wParam = WM_KEYUP Then
myhook = HotKey(keyMsg.vKey)
Exit Function
End If
Else
myhook = 0
End If
If code <> 0 Then
CallKeyHookProc = CallNextHookEx(0, code, wParam, lParam)
End If
End Function
Function HotKey(ByVal KeyCode As Integer) As Integer
If KeyCode = vbKeyQ Then
Shell App.Path & "\123.exe", vbNormalFocus
HotKey = 1
ElseIf KeyCode = vbKeyA Then
Shell App.Path & "\1234.exe", vbNormalFocus
HotKey = 1
Else
HotKey = 0
End If
End Function
'--------------------------------------------------------
上一个:VB编程问题关于input
下一个:Java和vb哪个有用