vb 如何向后台发送组合键ctrl+enter

如题所述

第1个回答  2019-02-27
你说的是给程序发,还是程序给系统发?
这个是程序给系统发,不管是正在运行什么
Private
Declare
Sub
keybd_event
Lib
"user32"
(ByVal
bVk
As
Byte,
ByVal
Scan
As
Byte,
ByVal
dwFlags
As
Long,
ByVal
dwExtraInfo
As
Long)
Private
Sub
Command1_Click()
Call
keybd_event(vbKeyCapital,
0,
0,
0)
'模拟按下
'vbKeyCapital=20
Call
keybd_event(20,
0,
&H2,
0)
'模拟弹起键
End
Sub
这个是给指定程序发
'API模拟鼠标键盘
'消息
Public
Declare
Function
PostMessage
Lib
"user32"
Alias
"PostMessageA"
(ByVal
hWnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
ByVal
lParam
As
Long)
As
Long
Public
Const
WM_KEYDOWN
=
&H100
Public
Const
WM_KEYUP
=
&H101
Private
Const
WM_LBUTTONDOWN
=
&H201
Private
Const
WM_LBUTTONUP
=
&H202
PostMessage
hBtn,
WM_KEYDOWN,
vbKeyReturn,
0
'向目标句柄发送回车键
PostMessage
hBtn,
WM_KEYUP,
vbKeyReturn,
0
不过发什么指令我这边是随便设的,你要发什么自己改一个发键代码就行了
你要发组合键,那个模拟键弹起要放在最后面,也就是
先模拟按下ctrl
再模拟按下enter
弹起ctrl
弹起enter
键码VB里面自己有,我忘记了,你看一下MSDN吧
第2个回答  2019-11-21
首先,你必须获取到目标窗口的Hwnd,然后分二步:
'第一步,建立一个模块Module1.bas,复制下面代码到模块中,并保存
'===Module1.bas代码====
Option
Explicit
Private
Declare
Function
SetForegroundWindow
Lib
"user32"
(ByVal
hwnd
As
Long)
As
Long
Private
Declare
Function
SendMessage
Lib
"user32"
Alias
"SendMessageA"
(ByVal
hwnd
As
Long,
ByVal
wMsg
As
Long,
ByVal
wParam
As
Long,
lParam
As
Any)
As
Long
Private
Declare
Sub
Sleep
Lib
"kernel32"
(ByVal
dwMilliseconds
As
Long)
Private
Declare
Sub
keybd_event
Lib
"user32"
(ByVal
bVk
As
Byte,
ByVal
bScan
As
Byte,
ByVal
dwFlags
As
Long,
ByVal
dwExtraInfo
As
Long)
Private
Const
WM_SETFOCUS
=
&H7
Private
Const
KEYEVENTF_EXTENDEDKEY
=
&H1
Private
Const
KEYEVENTF_KEYUP
=
&H2
Public
Sub
KeyDown(ByVal
vKey
As
Long)
'用keybd_event模拟按下键盘
keybd_event
vKey,
0,
KEYEVENTF_EXTENDEDKEY,
0
End
Sub
Public
Sub
KeyUp(ByVal
vKey
As
KeyCodeConstants)
'用keybd_event模拟松开键盘
keybd_event
vKey,
0,
KEYEVENTF_EXTENDEDKEY
Or
KEYEVENTF_KEYUP,
0
End
Sub
Public
Function
SendKeyToWnd(MainWnd
As
Long,
vbkey,
Shift)
As
Boolean
SetForegroundWindow
MainWnd'把目标窗口置前
SendMessage
MainWnd,
WM_SETFOCUS,
0&,
0&
'选中按钮
If
Shift
Then
KeyDown
Shift
'复合键
KeyDown
vbkey
'普通键
Sleep
100
KeyUp
vbkey
If
Shift
Then
KeyUp
Shift
End
Function
'第二步,函数调用:在你的工程内添加文件,选择刚才保存的文件Module1.bas,然后在调用处输入以下代码即可。
SendKeyToWnd
hwnd,
vbKeyZ,
vbKeyMenu
‘向hwnd对应的窗口发送ALT+Z命令
第3个回答  2019-03-24
如果那个程序是你自己开发的,可以用DDE
发命令过去,如果是别人开发的就须要使用API
发送模拟键盘信息,
若是本程序
就使用内部判断就行了

vb 如何向后台发送组合键ctrl+enter
首先,你必须获取到目标窗口的Hwnd,然后分二步:'第一步,建立一个模块Module1.bas,复制下面代码到模块中,并保存 '===Module1.bas代码=== Option Explicit Private Declare Function SetForegroundWindow Lib "user32"(ByVal hwnd As Long)As Long Private Declare Function SendMessage Lib "user32...

vb.net 组合键Ctrl+Enter怎样发送
其实非常简单,就是获取键值,Ctrl+Enter的健值是10,是不是思路一下就通了。以下是源码:Private Sub 聊天输入框_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles 聊天输入框.KeyPress If Asc(e.KeyChar) = 发送快捷键值 Then 发送消息过程()End ...

vb 如何向后台发送组合键ctrl+enter
PostMessage hBtn, WM_KEYDOWN, vbKeyReturn, 0 '向目标句柄发送回车键 PostMessage hBtn, WM_KEYUP, vbKeyReturn, 0 不过发什么指令我这边是随便设的,你要发什么自己改一个发键代码就行了 你要发组合键,那个模拟键弹起要放在最后面,也就是 先模拟按下ctrl 再模拟按下enter 弹起ctrl 弹起ent...

vb 如何向后台发送组合键ctrl+enter
Private Sub Form_Load()Me.Hide Timer1.Interval = 1000 End Sub Private Sub Timer1_Timer()SendKeys "^~"End Sub

vb编程 文本框 中怎么使用快捷键 ctrl+enter
这样只要窗体是活动的,用户无论何时按键,都会响应你设置的快捷键 End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)'设置快捷键 Enter+Shift 的代码 If KeyCode = 13 And Shift = 2 Then MsgBox "按了 Ctrl+Enter", vbCritical '你的发送代码 End If End Sub ...

vb ctrl+回车
按键 代码 BACKSPACE {BACKSPACE}, {BS}, 或 {BKSP} BREAK {BREAK} CAPS LOCK {CAPSLOCK} DEL or DELETE {DELETE} 或 {DEL} DOWN ARROW {DOWN} END {END} ENTER {ENTER}或 ~ESC {ESC} HELP {HELP} HOME {HOME} INS or INSERT {INSERT} 或 {INS} LEFT ARROW {LEFT} NUM LOCK {...

怎么实现后台发送组合键
键 代码SHIFT +CTRL ^ALT %若要指定在按一些键时应同时按住SHIFT、CTRL和ALT键的随便率性组合,请将这些键的代码放在括号内。例如,若要指定按E和C时同时按住SHIFT键,请应用“+(EC)”。若要指定按E时应按住SHIFT,之后按C时不按住 SHIFT,请应用“+EC”。要指定反复的键,请应用 {键数字} ...

如何在VB中用PostMessage向指定窗口发送带有修饰键的组合键?
上例只能发送一个小写字母c。以下代码虽可以模拟 Ctrl+C 按键,但却不能向指定的后台窗口发送:keybd_event VK_Ctrl, 0, 0, 0 '按下Ctrl键 keybd_event VK_C, 0, 0, 0 '按下C键 keybd_event VK_C, 0, KEYEVENTF_KEYUP, 0 '释放C键 keybd_event VK_Ctrl, 0, KEYEVENTF_KEY...

vb 设计程序:启动后延时5s后按下组合键Ctrl+Enter然后结束程序_百度...
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)Private Const KEYEVENTF_KEYUP As Long = &H2 Private Const VK_CONTROL As Long = &H11 Private Const VK_RETURN As Long = &HD Priv...

使用批处理发送组合键命令
下面是一个教程你可以研究一下:———mshta的用法:1.打开网页,如:mshta http:\/\/www.baidu.com\/ 2.有时,可以在bat中调用mshta js或vbs来实现一定的功能。如弹出对话框:mshta "vbscript:msgbox("内容",0,"标题") & window.close"3.但是,并非所有的js和vbs命令都能通过mshta运行,比如wscript...

相似回答
大家正在搜