sendkeys 的用法(MSDN):
SendKeys 语句
将一个或多个按键消息发送到活动窗口,就如同在键盘上进行输入一样。
语法
SendKeys string[, wait]
SendKeys 语句的语法具有以下几个命名参数:
部分
描述
string |
必需的。字符串表达式,指定要发送的按键消息。 |
Wait |
可选的。指定等待方式的 BooleandefBooleanDataType@veendf98.chm 值。如果为 False(缺省值),则控件在按键发送出去之后立刻返回到过程。如果为 True,则按键消息必须在控件返回到过程之前加以处理。 |
说明
每个按键由一个或多个字符表示。为了指定单一键盘字符,必须按字符本身的键。例如,为了表示字母 A,可以用 "A"
作为 string。为了表示多个字符,就必须在字符后面直接加上另一个字符。例如,要表示 A、B 及 C,可用 "ABC"
作为 string。
对 SendKeys 来说,加号 (+)、插入符 (^)、百分比符号 (%)、上划线 (~) 及圆括号 ( ) 都具有特殊意义。为了指定上述任何一个字符,要将它放在大括号 ({}) 当中。例如,要指定正号,可用 {+}
表示。方括号 ([ ]) 对 SendKeys 来说并不具有特殊意义,但必须将它们放在大括号中。在其它应用程序中,方括号有特殊意义,在出现动态数据交换 (DDE) 的时候,它可能具有重要意义。为了指定大括号字符,请使用 {{}
及 {}}。
为了在按下按键时指定那些不显示的字符,例如 ENTER 或 TAB 以及那些表示动作而非字符的按键,请使用下列代码:
按键
代码
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 |
{NUMLOCK} |
PAGE DOWN |
{PGDN} |
PAGE UP |
{PGUP} |
PRINT SCREEN |
{PRTSC} |
RIGHT ARROW |
{RIGHT} |
SCROLL LOCK |
{SCROLLLOCK} |
TAB |
{TAB} |
UP ARROW |
{UP} |
F1 |
{F1} |
F2 |
{F2} |
F3 |
{F3} |
F4 |
{F4} |
F5 |
{F5} |
F6 |
{F6} |
F7 |
{F7} |
F8 |
{F8} |
F9 |
{F9} |
F10 |
{F10} |
F11 |
{F11} |
F12 |
{F12} |
F13 |
{F13} |
F14 |
{F14} |
F15 |
{F15} |
F16 |
{F16} |
为了指定那些与 SHIFT、CTRL 及 ALT 等按键结合的组合键,可在这些按键码的前面放置一个或多个代码,这些代码列举如下:
按键
代码
SHIFT |
+ |
CTRL |
^ |
ALT |
% |
为了说明在按下其它按键时应同时按下 SHIFT、CTRL、及 ALT 的任意组合键,请把那些按键的码放在括号当中。例如,为了说明按下 E 与 C 的时候同时按下 SHIFT 键,请使用 "+(EC)
"。为了说明在按下 E 的时候同时按下 SHIFT 键,但接着按 C 而不按 SHIFT,则使用 "+EC
"。
为了指定重复键,使用 {key number}
的形式。必须在 key
与 number
之间放置一个空格。例如,{LEFT 42}
意指 42 次按下 LEFT ARROW 键;{h 10}
则是指 10 次按下 H 键。
注意 不能用 SendKeys 将按键消息发送到这样一个应用程序,这个应用程序并没有被设计成在 Microsoft Windows or Macintosh中运行。Sendkeys 也无法将 PRINT SCREEN 按键 {PRTSC
} 发送到任何应用程序。
我们如果想发送键命令,可以用 SENDKEYS ,但要发送 WINDOWS 微标键怎么做?(MSDN中没有给出WINDOWS键 的键码)
下面是可以执行的代码:
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 VK_LWIN = &H5B 'Left Windows key (Microsoft Natural keyboard)
Private Const VK_RWIN = &H5C 'Right Windows key (Natural keyboard)
Private Sub Command1_Click() 'left windows
keybd_event VK_LWIN, 0, &H1, 0
keybd_event VK_LWIN, 0, &H2, 0
End Sub
Private Sub Command2_Click() 'right windows
keybd_event VK_RWIN, 0, &H1, 0
keybd_event VK_RWIN, 0, &H2, 0
End Sub
详细的解释可参看SENDKEYS 类(http://www.vbaccelerator.com/home/VB/Tips/SendKeys_using_the_API/SendKeys_Demonstration_zip_cSendKeys_cls.asp):
vbAccelerator - Contents of code file: cSendKeys.clsVERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cSendKeys"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Public Enum MoreKeyConstants
VK_LWIN = &H5B 'Left Windows key (Microsoft Natural keyboard)
VK_RWIN = &H5C 'Right Windows key (Natural keyboard)
VK_APPS = &H5D 'Applications key (Natural keyboard)
VK_SLEEP = &H5F 'Computer Sleep key
VK_RMENU = &HA5 ' Right MENU key
VK_BROWSER_BACK = &HA6 'Windows 2000/XP: Browser Back key
VK_BROWSER_FORWARD = &HA7 'Windows 2000/XP: Browser Forward key
VK_BROWSER_REFRESH = &HA8 'Windows 2000/XP: Browser Refresh key
VK_BROWSER_STOP = &HA9 'Windows 2000/XP: Browser Stop key
VK_BROWSER_SEARCH = &HAA 'Windows 2000/XP: Browser Search key
VK_BROWSER_FAVORITES = &HAB 'Windows 2000/XP: Browser Favorites key
VK_BROWSER_HOME = &HAC 'Windows 2000/XP: Browser Start and Home key
VK_VOLUME_MUTE = &HAD 'Windows 2000/XP: Volume Mute key
VK_VOLUME_DOWN = &HAE 'Windows 2000/XP: Volume Down key
VK_VOLUME_UP = &HAF 'Windows 2000/XP: Volume Up key
VK_MEDIA_NEXT_TRACK = &HB0 'Windows 2000/XP: Next Track key
VK_MEDIA_PREV_TRACK = &HB1 'Windows 2000/XP: Previous Track key
VK_MEDIA_STOP = &HB2 'Windows 2000/XP: Stop Media key
VK_MEDIA_PLAY_PAUSE = &HB3 'Windows 2000/XP: Play/Pause Media key
VK_LAUNCH_MAIL = &HB4 'Windows 2000/XP: Start Mail key
VK_LAUNCH_MEDIA_SELECT = &HB5 'Windows 2000/XP: Select Media key
VK_LAUNCH_APP1 = &HB6 'Windows 2000/XP: Start Application 1 key
VK_LAUNCH_APP2 = &HB7 'Windows 2000/XP: Start Application 2 key
VK_OEM_1 = &HBA 'Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the ';:' key
VK_OEM_PLUS = &HBB 'Windows 2000/XP: For any country/region, the '+' key
VK_OEM_COMMA = &HBC 'Windows 2000/XP: For any country/region, the ',' key
VK_OEM_MINUS = &HBD 'Windows 2000/XP: For any country/region, the '-' key
VK_OEM_PERIOD = &HBE 'Windows 2000/XP: For any country/region, the '.' key
VK_OEM_2 = &HBF 'Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the '/?' key
VK_OEM_3 = &HC0 'Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the '`~' key
' C1D7 Reserved
' D8DA Unassigned
VK_OEM_4 = &HDB 'Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the '[{' key
VK_OEM_5 = &HDC 'Used for miscellaneous characters; it can vary by keyboard.
Windows 2000/XP: For the US standard keyboard, the '|' key
VK_OEM_6 = &HDD 'Used for miscellaneous characters; it can vary by keyboard
Windows 2000/XP: For the US standard keyboard, the ']}' key
VK_OEM_7 = &HDE ' Used for miscellaneous characters; it can vary by
keyboard. Windows 2000/XP: For the US standard keyboard, the
'single-quote/double-quote' key
VK_OEM_8 = &HDF 'Used for miscellaneous characters; it can vary by keyboard.
E0 Reserved
'- E1 OEM specific
VK_OEM_102 = &HE2 'Windows 2000/XP: Either the angle bracket key or the
backslash key on the RT 102-key keyboard
' E3E4 OEM specific
VK_PROCESSKEY = &HE5 'Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME
PROCESS key
' E6 OEM specific
VK_PACKET = &HE7 'Windows 2000/XP: Used to pass Unicode characters as if
they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual
Key value used for non-keyboard input methods. For more information, see
Remark in KEYBDINPUT, SendInput, WM_KEYDOWN, and WM_KEYUP
' E8 Unassigned
' E9F5 OEM specific
VK_ATTN = &HF6 'Attn key
VK_CRSEL = &HF7 'CrSel key
VK_EXSEL = &HF8 'ExSel key
VK_EREOF = &HF9 'Erase EOF key
VK_PLAY = &HFA 'Play key
VK_ZOOM = &HFB 'Zoom key
VK_NONAME = &HFC 'Reserved for future use
VK_PA1 = &HFD 'PA1 key
VK_OEM_CLEAR = &HFE 'Clear key
End Enum
Private m_colKeyMap As New Collection
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 KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Declare Function GetVersion Lib "kernel32" () As Long
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" ( _
ByVal cChar As Byte) As Integer
Private Declare Function VkKeyScanW Lib "user32" ( _
ByVal cChar As Integer) As Integer
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Function nextChar(ByRef sString As String, ByVal iPos As Long, Optional
ByVal lLen As Long = 0) As String
If (lLen = 0) Then lLen = Len(sString)
If (iPos + 1 <= lLen) Then
分享到:
相关推荐
SendKeys模拟键盘输入实例源代码
VB6中SendKeys的基本应用[VB6中SendKeys的基本应用]-精品源代码
精彩编程与编程技巧-突破SendKeys的限制 ...
vbsQQ登录脚本 WshShell.AppActivate WshShell.SendKeys
记事本自动保存源代码,稍加修改就可以自动保存任何文件 用VB6编写 icecept@163.com QQ:543375508
'让SendKeys可以发送中文,clip.exe在windows2003里有
brew install socsieng/tap/sendkeys 它包括对鼠标命令的扩展支持。 我不再维护这个库并鼓励你使用 Swift 版本。 macOS 的 SendKeys 这是一个 CLI 工具,用于将密钥发送到给定的应用程序以模拟给定速度的打字。 ...
sendkeys.py-主代码文件, sendkeys.xml-GUI表单文件。 文本编辑器是: in Linux - Gedit, in Windows - Notepad. 鼠标动作不包括在内。 支持的符号列表: 1234567890 abcdefghijklmnopqrstuvwxyz ...
SendKeys 模拟键盘操作,将一个或多个按键指令发送到指定Windows窗口来控制应用程序运行,下面有很多的vbs结合sendkyes的实例代码,方便大家学习
精彩编程与编程技巧-用SendKeys来捉屏 ...
SendKeys是一个macOS命令行应用程序,用于自动执行击键和鼠标事件。 它是用于自动化屏幕记录的输入和鼠标事件的出色工具。 这是的Swift重写。 用法 基本用法: sendkeys --application-name " Notes " --...
这是一个用于快速查找ASCII / ISO 8859-1(Latin-1)字符的数值的小工具。 双击一个字符将通过按键将其传递到活动窗口/文本框。 我主要是作为控制字符代码的快速查找表而开发的。 右键单击以获取选项。
下表显示了十六进制符号常量名,,由系统所使用的虚拟键码和鼠标或键盘等值。这些代码数字顺序列出。
telnet自动登录路由器、交换机等网络设备的批处理文件代码2008-02-17 14:07@echo off echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs echo WScript.Sleep 300 >>telnet_tmp.vbs echo sh.Send...
WshShell.SendKeys "^v" WshShell.SendKeys i WshShell.SendKeys "%s" Next 其中WshShell.AppActivate "夜雨"引号中是要刷屏的群或好友的名字; for i=1 to 10为设置的发送次数。 将其保存为.vbs文件,如:qq....
问题背景: 使用基于Python的Selenium...driver.find_element_by_id(kw).send_keys(2020) 运行报错如下: File D:/PythonWorkSpace/AutomaticTesting/Demo.py, line 8, in driver.find_element_by_id(kw).send_key
[玩一玩] 把下面代码保存为sendkeys.js,然后双击运行。 代码如下:var WshShell = new ActiveXObject(“WScript.Shell”); WshShell.Run(“Notepad”); WScript.Sleep(100); WshShell.AppActivate(“Notepad”)...
VBA代码,使用Sendkeys将数据从其他软件复制到Excel
'对 SendKeys 来 说 , 加 号 (+)、 插 入 符 (^)、 百 分 比 符 号 (%)、 上 划 线 (~) 及 圆 括 号 ( ) 都 具 有 特 殊 意 义 。 为 了 指 定 上 述 任 何 一 个 字 符 , 要 将 它 放 在 大 括 号 ({}) 当 中 。...