问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

VB设置热键

发布网友 发布时间:2022-04-28 11:29

我来回答

2个回答

热心网友 时间:2023-10-05 11:44

这个也简单,我给你做了个全局热键:代码我都帮你综合了你自己别忘了控件基本不会出错的!1楼下的P话一样的你要窗体上KeyPress事件我还不如直接点按钮呢你说是不?还有你的窗体不是Form1的话就自己在模块里修改下嘎嘎
窗体代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Text4 = Val(Text2) * Val(Text3)
Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。
End Sub

Private Sub Form_Load()
HooK
Command1.Caption = "开始自动喊话"
Command2.Caption = "结束自动喊话"
Timer1.Enabled = False
Text1.Text = "请在这里输入你要喊话的内容!" '这些代码意思是当窗体载入的时候,将command1,command2,text1的内容换成后面的。并关闭time控件!
End Sub

Private Sub Label3_Click()
Shell "explorer.exe http://user.qzone.qq.com/282718156"
End Sub

Private Sub Text3_Change()
For i = 0 To 1
If Val(Text3.Text) < 1 Or Val(Text3.Text) > 60 Then
MsgBox "请输1秒到60秒之间的数值,建议大于10秒!" '这个代码的意思检测text3里面输入的数字!当小于1秒或者大于60秒时清空text3里面的数值!
Text3.Text = ""
Text3.SetFocus
Exit Sub
End If
Next i

End Sub

Private Sub Timer1_Timer()
Timer1.Interval = Text4.Text '这个代码的意思是 time控件的时间属性由text4提供。并在规定的时间到达时,在鼠标的准星处输入text1中的内容,并按下enter键。
SendKeys Text1.Text
SendKeys "{enter}"
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHooK
End Sub

模块代码:
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 = vbKeyF2 Then '开始
Form1.Text4 = Val(Text2) * Val(Text3)
Form1.Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。

ElseIf p.vkCode = vbKeyF3 Then '暂停
Form1.Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。

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

这样你只要在任何地方按下F2都能激活窗体代码开始,按下F3都能暂停!
有什么不懂的可以留个邮箱哈

热心网友 时间:2023-10-05 11:45

Private Sub Form_KeyPress(KeyAscii As Integer)
On Error Resume Next
Dim Key
Key = Chr(KeyAscii)
If Key = "x" Then
Call Command1_Click()
End If
End Sub '按x就会启动Command1_Click()
--是用这个吗

热心网友 时间:2023-10-05 11:44

这个也简单,我给你做了个全局热键:代码我都帮你综合了你自己别忘了控件基本不会出错的!1楼下的P话一样的你要窗体上KeyPress事件我还不如直接点按钮呢你说是不?还有你的窗体不是Form1的话就自己在模块里修改下嘎嘎
窗体代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Text4 = Val(Text2) * Val(Text3)
Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。
End Sub

Private Sub Form_Load()
HooK
Command1.Caption = "开始自动喊话"
Command2.Caption = "结束自动喊话"
Timer1.Enabled = False
Text1.Text = "请在这里输入你要喊话的内容!" '这些代码意思是当窗体载入的时候,将command1,command2,text1的内容换成后面的。并关闭time控件!
End Sub

Private Sub Label3_Click()
Shell "explorer.exe http://user.qzone.qq.com/282718156"
End Sub

Private Sub Text3_Change()
For i = 0 To 1
If Val(Text3.Text) < 1 Or Val(Text3.Text) > 60 Then
MsgBox "请输1秒到60秒之间的数值,建议大于10秒!" '这个代码的意思检测text3里面输入的数字!当小于1秒或者大于60秒时清空text3里面的数值!
Text3.Text = ""
Text3.SetFocus
Exit Sub
End If
Next i

End Sub

Private Sub Timer1_Timer()
Timer1.Interval = Text4.Text '这个代码的意思是 time控件的时间属性由text4提供。并在规定的时间到达时,在鼠标的准星处输入text1中的内容,并按下enter键。
SendKeys Text1.Text
SendKeys "{enter}"
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHooK
End Sub

模块代码:
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 = vbKeyF2 Then '开始
Form1.Text4 = Val(Text2) * Val(Text3)
Form1.Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。

ElseIf p.vkCode = vbKeyF3 Then '暂停
Form1.Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。

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

这样你只要在任何地方按下F2都能激活窗体代码开始,按下F3都能暂停!
有什么不懂的可以留个邮箱哈

热心网友 时间:2023-10-05 11:45

Private Sub Form_KeyPress(KeyAscii As Integer)
On Error Resume Next
Dim Key
Key = Chr(KeyAscii)
If Key = "x" Then
Call Command1_Click()
End If
End Sub '按x就会启动Command1_Click()
--是用这个吗

热心网友 时间:2023-10-05 11:44

这个也简单,我给你做了个全局热键:代码我都帮你综合了你自己别忘了控件基本不会出错的!1楼下的P话一样的你要窗体上KeyPress事件我还不如直接点按钮呢你说是不?还有你的窗体不是Form1的话就自己在模块里修改下嘎嘎
窗体代码:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Sub Command1_Click()
Text4 = Val(Text2) * Val(Text3)
Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。
End Sub

Private Sub Form_Load()
HooK
Command1.Caption = "开始自动喊话"
Command2.Caption = "结束自动喊话"
Timer1.Enabled = False
Text1.Text = "请在这里输入你要喊话的内容!" '这些代码意思是当窗体载入的时候,将command1,command2,text1的内容换成后面的。并关闭time控件!
End Sub

Private Sub Label3_Click()
Shell "explorer.exe http://user.qzone.qq.com/282718156"
End Sub

Private Sub Text3_Change()
For i = 0 To 1
If Val(Text3.Text) < 1 Or Val(Text3.Text) > 60 Then
MsgBox "请输1秒到60秒之间的数值,建议大于10秒!" '这个代码的意思检测text3里面输入的数字!当小于1秒或者大于60秒时清空text3里面的数值!
Text3.Text = ""
Text3.SetFocus
Exit Sub
End If
Next i

End Sub

Private Sub Timer1_Timer()
Timer1.Interval = Text4.Text '这个代码的意思是 time控件的时间属性由text4提供。并在规定的时间到达时,在鼠标的准星处输入text1中的内容,并按下enter键。
SendKeys Text1.Text
SendKeys "{enter}"
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnHooK
End Sub

模块代码:
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 = vbKeyF2 Then '开始
Form1.Text4 = Val(Text2) * Val(Text3)
Form1.Timer1.Enabled = True
MsgBox "自动喊话开启成功!谢谢您的使用!" '这个一段代码的意思,当按下command1按钮时,将text2和text3的数值想乘,然后把数值赋予给text4,并开启time控件开始喊话。

ElseIf p.vkCode = vbKeyF3 Then '暂停
Form1.Timer1.Enabled = False
MsgBox "自动喊话已关闭!谢谢您的使用!" '这段代码的意思是关闭time控件,关闭自动喊话器。

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

这样你只要在任何地方按下F2都能激活窗体代码开始,按下F3都能暂停!
有什么不懂的可以留个邮箱哈

热心网友 时间:2023-10-05 11:45

Private Sub Form_KeyPress(KeyAscii As Integer)
On Error Resume Next
Dim Key
Key = Chr(KeyAscii)
If Key = "x" Then
Call Command1_Click()
End If
End Sub '按x就会启动Command1_Click()
--是用这个吗
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
新生儿脐疝的诊断与鉴别 小儿脐疝发病原因 导致新生儿脐疝发作的原因有哪些? 腾讯视频2023年10月24日免费会员账号分享-腾讯视频2023年10月24日免 ... 百度网盘激活码免费领取2024 百度网盘激活码免费领取最新分享 我是男生 今年18周岁 我身高172是不是完蛋了 我还会长吗? 估计还能长... 开荒保洁一平米多少钱 物业开荒费用包括哪些 公司保洁开荒多少钱一平 开封灌汤包哪家正宗 开封哪家灌汤包最好吃 vb.net怎样给MenuItem设置热键? VB里怎么设置快捷键 如:F1开启 F2关闭 vb怎样使用热键 vb 按钮快捷键怎么设置 vb 热键设置 VB中如何对命令按钮分别设置快捷键和热键?Alt+字母,Ctrl+字母分明代表哪个键? vb按钮如何设置快捷键, 请问怎样在 VB 中设置系统热键? VB 如何设置快捷键? vb怎么设置快捷键? 百度糯米火车票退票怎么退票 VB中如何设置热键和快捷键? 在百度糯米上订的消费券怎么使用啊 我在百度订票在12306查没有定订单但手机以来信息,定票成功,以出票成 百度糯米关注的东西在哪里看 百度糯米团升级版本之后为什么所有的没使用的团购券都没有了,以前的消费记录也都没了,怎么找回记录? 百度糯米如何退火车票 我百度糯米订的火车票退款还没到怎么办? 如何删除百度叫车订单记录? 如何删除百度糯米中已完成的电影订单(购票记录)? 在VB中如何设置快捷键? VB中如何为程序设置快捷键 VB怎么设置热键啊 vb怎么设置全局热键 vb如何设置按钮控件的快捷键 手机屏幕上酷狗歌词怎么解锁? 如果酷狗的桌面歌词被锁住了。怎么解锁? 织梦cms列表页如何实现瀑布流效果,谁有相关代码或者插件,可以给我吗,谢谢!!!!!!!!!!!! 办公室里有那种特别讨厌的人怎么办? 要怎么面对很讨厌的同事? 怎么与讨厌的同事相处,特别是同个办公室? 在公司遇到特别讨厌的人怎么跟她相处? 公司办公室有一位同事,我特别烦他,该如何与他相处呢? 在工作中,你是如何跟讨厌的人相处的? 面对非常讨厌的白眼狼同事,该如何与其相处? 心里很讨厌一个办公室同事,我该如何与她共事呢? 在办公室遇到不喜欢的人,究竟该怎么办呢? 遇到特别讨厌的人跟你共事,如何处理同事关系? 我心中的阳光 600字记叙文 遇到很讨厌的同事怎么办?