vb中按下ctrl键和松开ctrl的命令怎么写
1个回答
展开全部
在事件KeyDown和KeyUp中有个Shift。要判断Ctrl键是否按下,使用该常数。该参数用作位屏蔽。它可被用来测试任何键组合。
CtrlDown = (Shift And VbCtrlMask) > 0
ShiftDown = (Shift And vbShiftMask) > 0
AltDown = (Shift And VbAltMask) > 0
用命令按下和松开Ctrl键:
使用API函数keybd_event。
Const VK_CONTROL = &H11
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
这个函数模拟了键盘
行动
bVk Byte,欲模拟的虚拟键码,API中定义了一些键值,用API Text View看看是否有你需要的。
bScan Byte,键的OEM扫描码
dwFlags Long,零;或设为下述两个标志之一:
KEYEVENTF_EXTENDEDKEY 指出是一个扩展键,而且在前面冠以0xE0代码
KEYEVENTF_KEYUP 模拟松开一个键
dwExtraInfo Long,通常不用的一个值。使用的时候一般没管,填0
下面的代码是打开一个记事本,并发送Ctrl+O,使打开文件对话框出现
Const VK_CONTROL = &H11
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_Load()
Shell "notepad.exe", vbNormalFocus '运行记事本程序
keybd_event VK_CONTROL, 0, 0, 0 '按下Ctrl键
keybd_event vbKeyO, 0, 0, 0 '按下字母O键
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 '放开Ctrl键
keybd_event vbKeyO, 0, KEYEVENTF_KEYUP, 0 '放开字母O键
End Sub
CtrlDown = (Shift And VbCtrlMask) > 0
ShiftDown = (Shift And vbShiftMask) > 0
AltDown = (Shift And VbAltMask) > 0
用命令按下和松开Ctrl键:
使用API函数keybd_event。
Const VK_CONTROL = &H11
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
这个函数模拟了键盘
行动
bVk Byte,欲模拟的虚拟键码,API中定义了一些键值,用API Text View看看是否有你需要的。
bScan Byte,键的OEM扫描码
dwFlags Long,零;或设为下述两个标志之一:
KEYEVENTF_EXTENDEDKEY 指出是一个扩展键,而且在前面冠以0xE0代码
KEYEVENTF_KEYUP 模拟松开一个键
dwExtraInfo Long,通常不用的一个值。使用的时候一般没管,填0
下面的代码是打开一个记事本,并发送Ctrl+O,使打开文件对话框出现
Const VK_CONTROL = &H11
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_Load()
Shell "notepad.exe", vbNormalFocus '运行记事本程序
keybd_event VK_CONTROL, 0, 0, 0 '按下Ctrl键
keybd_event vbKeyO, 0, 0, 0 '按下字母O键
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 '放开Ctrl键
keybd_event vbKeyO, 0, KEYEVENTF_KEYUP, 0 '放开字母O键
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询