vbKeyLButton0x1鼠标左键vbKeyRButton0x2鼠标右键vbKeyCancel0x3CANCEL键vbKeyMButton0x4鼠标中键vbKeyBack0x8退格键vbKeyTab0x9TAB键vbKeyClear0xCCLEAR健vbKeyReturn0xD回车键vbKey…展开
我来答 分享 举报
1个回答
wangaochao1980
推荐于2016-04-16 · TA获得超过449个赞
Keycode 常数
可在代码中的任何地方用下列常数代替实际值:
常数 值 描述
vbKeyLButton 0x1 鼠标左键
vbKeyRButton 0x2 鼠标右键
vbKeyCancel 0x3 CANCEL 键
vbKeyMButton 0x4 鼠标中键
vbKeyBack 0x8 BACKSPACE 键
vbKeyTab 0x9 TAB 键
vbKeyClear 0xC CLEAR 键
vbKeyReturn 0xD ENTER 键
vbKeyShift 0x10 SHIFT 键
vbKeyControl 0x11 CTRL 键
vbKeyMenu 0x12 MENU 键
vbKeyPause 0x13 PAUSE 键
vbKeyCapital 0x14 CAPS LOCK 键
vbKeyEscape 0x1B ESC 键
vbKeySpace 0x20 SPACEBAR 键
vbKeyPageUp 0x21 PAGE UP 键
vbKeyPageDown 0x22 PAGE DOWN 键
vbKeyEnd 0x23 END 键
vbKeyHome 0x24 HOME 键
vbKeyLeft 0x25 LEFT ARROW 键
vbKeyUp 0x26 UP ARROW 键
vbKeyRight 0x27 RIGHT ARROW 键
vbKeyDown 0x28 DOWN ARROW 键
vbKeySelect 0x29 SELECT 键
vbKeyPrint 0x2A PRINT SCREEN 键
vbKeyExecute 0x2B EXECUTE 键
vbKeySnapshot 0x2C SNAPSHOT 键
vbKeyInsert 0x2D INSERT 键
vbKeyDelete 0x2E DELETE 键
vbKeyHelp 0x2F HELP 键
vbKeyNumlock 0x90 NUM LOCK 键
A 至 Z 键与 A – Z 字母的 ASCII 码相同:
常数 值 描述
vbKeyA 65 A 键
vbKeyB 66 B 键
vbKeyC 67 C 键
vbKeyD 68 D 键
vbKeyE 69 E 键
vbKeyF 70 F 键
vbKeyG 71 G 键
vbKeyH 72 H 键
vbKeyI 73 I 键
vbKeyJ 74 J 键
vbKeyK 75 K 键
vbKeyL 76 L 键
vbKeyM 77 M 键
vbKeyN 78 N 键
vbKeyO 79 O 键
vbKeyP 80 P 键
vbKeyQ 81 Q 键
vbKeyR 82 R 键
vbKeyS 83 S 键
vbKeyT 84 T 键
vbKeyU 85 U 键
vbKeyV 86 V 键
vbKeyW 87 W 键
vbKeyX 88 X 键
vbKeyY 89 Y 键
vbKeyZ 90 Z 键
0 至 9 键与数字 0 – 9 的 ASCII 码相同:
常数 值 描述
vbKey0 48 0 键
vbKey1 49 1 键
vbKey2 50 2 键
vbKey3 51 3 键
vbKey4 52 4 键
vbKey5 53 5 键
vbKey6 54 6 键
vbKey7 55 7 键
vbKey8 56 8 键
vbKey9 57 9 键
下列常数代表数字键盘上的键:
常数 值 描述
vbKeyNumpad0 0x60 0 键
vbKeyNumpad1 0x61 1 键
vbKeyNumpad2 0x62 2 键
vbKeyNumpad3 0x63 3 键
vbKeyNumpad4 0x64 4 键
vbKeyNumpad5 0x65 5 键
vbKeyNumpad6 0x66 6 键
vbKeyNumpad7 0x67 7 键
vbKeyNumpad8 0x68 8 键
vbKeyNumpad9 0x69 9 键
vbKeyMultiply 0x6A MULTIPLICATION SIGN (*) 键
vbKeyAdd 0x6B PLUS SIGN (+) 键
vbKeySeparator 0x6C ENTER 键
vbKeySubtract 0x6D MINUS SIGN (–) 键
vbKeyDecimal 0x6E DECIMAL POINT (.) 键
vbKeyDivide 0x6F DIVISION SIGN (/) 键
下列常数代表功能键:
常数 值 描述
vbKeyF1 0x70 F1 键
vbKeyF2 0x71 F2 键
vbKeyF3 0x72 F3 键
vbKeyF4 0x73 F4 键
vbKeyF5 0x74 F5 键
vbKeyF6 0x75 F6 键
vbKeyF7 0x76 F7 键
vbKeyF8 0x77 F8 键
vbKeyF9 0x78 F9 键
vbKeyF10 0x79 F10 键
vbKeyF11 0x7A F11 键
vbKeyF12 0x7B F12 键
vbKeyF13 0x7C F13 键
vbKeyF14 0x7D F14 键
vbKeyF15 0x7E F15 键
vbKeyF16 0x7F F16 键
本回答被提问者采纳
VB全局热键(快捷键)
VisualBasic编程源码
'窗体代码:
Private Declare Function GetActiveWindow Lib “user32” () As Long
Private Declare Function GetAsyncKeyState Lib “user32” (ByVal vKey As Long) As Integer
Private Sub Form_Load()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
'如果窗体失去焦点,热键无效
If GetActiveWindow <> Me.hwnd Then Exit Sub
'Esc退出程序
If GetAsyncKeyState(vbKeyEscape) Then KeyCode = 0: End
'F12最大化窗口
If GetAsyncKeyState(vbKeyF12) Then KeyCode = 0: Me.WindowState = 2
'F1窗口最小化
If GetAsyncKeyState(vbKeyF1) Then KeyCode = 0: Me.WindowState = 1
End Sub
'-------------------------------------------------------------------------------------------------------------------------
'相应的VB键码
常数------------------------------值-------------描述
vbKeyLButton-----------------[1]-------------鼠标左键
vbKeyRButton-----------------[2]-------------鼠标右键
vbKeyCancel-------------------[3]-------------CANCEL 键
vbKeyMButton-----------------[4]-------------鼠标中键
vbKeyBack---------------------[8]--------------BACKSPACE 键
vbKeyTab-----------------------[9]--------------TAB 键
vbKeyClear--------------------[12]-------------CLEAR 键
vbKeyReturn------------------[13]-------------ENTER 键
vbKeyShift---------------------[16]-------------SHIFT 键
vbKeyControl-----------------[17]-------------CTRL 键
vbKeyMenu-------------------[18]-------------Alt 菜单键
vbKeyPause------------------[19]-------------PAUSE 键
vbKeyCapital-----------------[20]-------------CAPS LOCK 键
vbKeyEscape-----------------[27]-------------ESC 键
vbKeySpace------------------[32]-------------SPACEBAR 键
vbKeyPageUp----------------[33]-------------PAGEUP 键
vbKeyPageDown------------[34]-------------PAGEDOWN 键
vbKeyEnd---------------------[35]-------------END 键
vbKeyHome------------------[36]-------------HOME 键
vbKeyLeft---------------------[37]-------------LEFT ARROW 键
vbKeyUp----------------------[38]-------------UP ARROW 键
vbKeyRight-------------------[39]-------------RIGHT ARROW 键
vbKeyDown------------------[40]-------------DOWN ARROW 键
vbKeySelect-----------------[41]-------------SELECT 键
vbKeyPrint-------------------[42]-------------PRINT SCREEN 键
vbKeyExecute--------------[43]--------------EXECUTE 键
vbKeySnapshot------------[44]--------------SNAP SHOT 键
vbKeyInser------------------[45]--------------INS 键
vbKeyDelete----------------[46]--------------DEL 键
vbKeyHelp------------------[47]---------------HELP 键
vbKeyNumlock------------[144]-------------NUM LOCK 键
A 键到 Z 键与其 ASCII 码的相应值 'A ’ 到 'Z ’ 是一致的
常数--------------------------值----------------------描述
vbKeyA---------------------[65]---------------------A 键
vbKeyB---------------------[66]---------------------B 键
vbKeyC---------------------[67]---------------------C 键
vbKeyD---------------------[68]---------------------D 键
vbKeyE---------------------[69]---------------------E 键
vbKeyF---------------------[70]---------------------F 键
vbKeyG---------------------[71]---------------------G 键
vbKeyH---------------------[72]---------------------H 键
vbKeyI-----------------------[73]---------------------I 键
vbKeyJ----------------------[74]---------------------J 键
vbKeyK----------------------[75]---------------------K 键
vbKeyL----------------------[76]---------------------L 键
vbKeyM---------------------[77]---------------------M 键
vbKeyN---------------------[78]---------------------N 键
vbKeyO---------------------[79]---------------------O 键
vbKeyP---------------------[80]---------------------P 键
vbKeyQ---------------------[81]---------------------Q 键
vbKeyR---------------------[82]---------------------R 键
vbKeyS---------------------[83]---------------------S 键
vbKeyT---------------------[84]---------------------T 键
vbKeyU---------------------[85]---------------------U 键
vbKeyV---------------------[86]---------------------V 键
vbKeyW---------------------[87]---------------------W 键
vbKeyX---------------------[88]---------------------X 键
vbKeyY---------------------[89]---------------------Y 键
vbKeyZ---------------------[90]---------------------Z 键
0 键到 9 键与其 ASCII 码的相应值 '0 ’ 到 '9 ’ 是一致的
常数------------------值------描述
vbKey0-------------[48]-----0 键
vbKey1-------------[49]-----1 键
vbKey2-------------[50]-----2 键
vbKey3-------------[51]-----3 键
vbKey4-------------[52]-----4 键
vbKey5-------------[53]-----5 键
vbKey6-------------[54]-----6 键
vbKey7-------------[55]-----7 键
vbKey8-------------[56]-----8 键
vbKey9-------------[57]-----9 键
数字小键盘上的键
常数------------------------值------------描述
vbKeyNumpad0--------[96]----------0 键
vbKeyNumpad1--------[97]----------1 键
vbKeyNumpad2--------[98]----------2 键
vbKeyNumpad3--------[99]----------3 键
vbKeyNumpad4--------[100]--------4 键
vbKeyNumpad5--------[101]--------5 键
vbKeyNumpad6--------[102]--------6 键
vbKeyNumpad7--------[103]--------7 键
vbKeyNumpad8--------[104]--------8 键
vbKeyNumpad9--------[105]--------9 键
vbKeyMultiply-----------[106]-------乘号 (*) 键
vbKeyAdd----------------[107]-------加号 (+) 键
vbKeySeparator--------[108]-------ENTER 键(在数字小键盘上)
vbKeySubtract----------[109]-------减号 (-) 键
vbKeyDecimal----------[110]-------小数点 (.) 键
vbKeyDivide------------[111]--------除号 (/) 键
功能键
常数---------------值--------------描述
vbKeyF1--------[112]------------F1 键
vbKeyF2--------[113]------------F2 键
vbKeyF3--------[114]------------F3 键
vbKeyF4--------[115]------------F4 键
vbKeyF5--------[116]------------F5 键
vbKeyF6--------[117]------------F6 键
vbKeyF7--------[118]------------F7 键
vbKeyF8--------[119]------------F8 键
vbKeyF9--------[120]------------F9 键
vbKeyF10------[121]------------F10 键
vbKeyF11------[122]------------F11 键
vbKeyF12------[123]------------F12 键
vbKeyF13------[124]------------F13 键
vbKeyF14------[125]------------F14 键
vbKeyF15------[126]------------F15 键
vbKeyF16------[127]------------F16 键
Private Declare Sub keybd_event Lib “user32” (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Text1.text = “C:\Users\28261\Desktop\文本框密码登录程序.exe”
End Sub
Private Sub command1_Click()
'打开目标程序
Shell “密码登录程序.exe”, vbNormalFocus
Sleep 3000
'打开目标目录
shell “explorer.exe C:\Users\28261\Desktop”, vbNormalFocus
Sleep 3000
Call Command2_Click
'暂停一段时间,以确保目标目录已打开
Sleep 3000
Dim S As String
S = Text1.Text
Shell S, vbNormalFocus
Sleep 3000
'打开目标目录
shell “explorer.exe C:\Users\28261\Desktop”, vbNormalFocus
Sleep 3000
' 打开目标目录
Shell "explorer.exe C:\Users\28261\Documents", vbNormalFocus
' 暂停一段时间,以确保目标目录已打开
Sleep 3000
’ 按下Ctrl+C复制
Call keybd_event(17, 0, 0, 0) '模拟按下 'ctrl
Call keybd_event(67, 0, 0, 0) '模拟按下 'ctrl
Call keybd_event(67, 0, &H2, 0) '模拟弹起键
Call keybd_event(17, 0, &H2, 0) '模拟弹起键
Sleep 500
'按下Ctrl+V粘贴
Call keybd_event(17, 0, 0, 0) '模拟按下 'ctrl
Call keybd_event(86, 0, 0, 0) '模拟按下 'ctrl
Call keybd_event(86, 0, &H2, 0) '模拟弹起键
Call keybd_event(17, 0, &H2, 0) '模拟弹起键
Sleep 500
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(8, 0, 0, 0) '模拟按下 'backspace
Call keybd_event(8, 0, &H2, 0) '模拟弹起键
Call keybd_event(8, 0, 0, 0) '模拟按下 'backspace
Call keybd_event(8, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(8, 0, 0, 0) '模拟按下 'backspace
Call keybd_event(8, 0, &H2, 0) '模拟弹起键
Call keybd_event(8, 0, 0, 0) '模拟按下 'backspace
Call keybd_event(8, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
Call keybd_event(13, 0, 0, 0) '模拟按下 'enter
Call keybd_event(13, 0, &H2, 0) '模拟弹起键
Sleep 1000
End Sub
Private Sub Command1_Click()
' 打开文本文件
ShellExecute Me.hWnd, "Open", "C:\Users\28261\Desktop\查找文件并输入内容程序源代码\空.txt", vbNullString, vbNullString, vbNormalFocus
Sleep 300
End Sub
Private Sub Command2_Click()
’ 打开应用程序
filePath = “C:\Users\28261\Desktop\查找文件并输入内容程序源代码\文本框密码登录程序.exe”
ShellExecute Me.hWnd, “Open”, filePath, vbNullString, vbNullString, vbNormalFocus
End Sub
Private Sub Command3_Click()
Dim filePath As String
Dim fileContent As String
' 获取文件路径和内容
filePath = "C:\Users\28261\Desktop\查找文件并输入内容程序源代码\空.txt"
fileContent = Text1.text
' 打开文本文件
ShellExecute Me.hWnd, "Open", filePath, vbNullString, vbNullString, vbNormalFocus
End Sub
Private Sub Command1_Click()
Dim password As String
Dim possibleChars As String
Dim currentChar As String
Dim i As Integer
Dim j As Integer
’ 暴力穷举算法
For i = 1 To Len(possibleChars)
For j = 1 To Len(password)
keybd_event Asc(Mid(password, j, 1)), 0, 0, 0 ’ 按下按键
Sleep 100 ’ 等待一段时间
keybd_event Asc(Mid(password, j, 1)), 0, KEYEVENTF_KEYUP, 0 ’ 释放按键
Sleep 100 ’ 等待一段时间
Next j
' 如果还有更多密码组合,继续尝试
If i < Len(possibleChars) Then
currentChar = Mid(possibleChars, i + 1, 1)
keybd_event Asc(currentChar), 0, 0, 0 ' 按下按键
Sleep 100 ' 等待一段时间
keybd_event Asc(currentChar), 0, KEYEVENTF_KEYUP, 0 ' 释放按键
Sleep 100 ' 等待一段时间
End If
Next i
End Sub
Private Sub Command1_Click()
Dim password As String
Dim possibleChars As String
Dim i As Integer
password = “1234” ’ 输入密码
possibleChars = “0123456789” ’ 可能的字符集合
’ 模拟键盘输入
For i = 1 To Len(password)
keybd_event Asc(Mid(password, i, 1)), 0, 0, 0 ’ 按下按键
Sleep 100 ’ 等待一段时间
keybd_event Asc(Mid(password, i, 1)), 0, KEYEVENTF_KEYUP, 0 ’ 释放按键
Sleep 100 ’ 等待一段时间
Next i
’ 模拟回车键
keybd_event VK_RETURN, 0, 0, 0 ’ 按下回车键
Sleep 100 ’ 等待一段时间
keybd_event VK_RETURN, 0, KEYEVENTF_KEYUP, 0 ’ 释放回车键
End Sub
’ 执行网络浏览器的搜索命令
Shell “explorer.exe http://www.baidu.com/s?wd=指定文件名”, vbNormalFocus
’ 暂停一段时间,以确保搜索结果已加载
Sleep 3000
’ 模拟Ctrl+A全选操作
keybd_event VK_CONTROL, 0, 0, 0
keybd_event Asc(“A”), 0, 0, 0
keybd_event Asc(“A”), 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
’ 模拟Ctrl+C复制操作
keybd_event VK_CONTROL, 0, 0, 0
keybd_event Asc(“C”), 0, 0, 0
keybd_event Asc(“C”), 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0
' 打开目标目录
Shell "explorer.exe 目标目录路径", vbNormalFocus
' 暂停一段时间,以确保目标目录已打开
Sleep 1000
' 模拟Ctrl+V粘贴操作
keybd_event VK_CONTROL, 0, 0, 0
keybd_event Asc("V"), 0, 0, 0
keybd_event Asc("V"), 0, KEYEVENTF_KEYUP, 0
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0