我们如何使用 vbs 模拟键盘键? [英] how can we simulate keyboard keys using vbs?

查看:124
本文介绍了我们如何使用 vbs 模拟键盘键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道可能是最常见的形式:

set wShell = createObject("wscript.shell")wShell.sendKeys ":){ENTER}"

这种不常见且有限的方式:

Set ShellApp = CreateObject("Shell.Application")ShellApp.WindowSwitcher

我们可以hackishly 使用 sleep 如果我们想要一个依赖于其他事件的键序列:

WScript.sleep 987wShell.sendKeys "foo{!}~"第 789 章wShell.sendKeys "^a^c"

而且我们不能真正保持按键按下但我们可以重复多次:

wShell.sendKeys "{LEFT 42}"

现在……我错过了什么吗?

解决方案

是的,我可能遗漏了一些东西.

同时我认为这个有用提交的参考可能仍然有用有用如果无耻地在此处改编:

<块引用>

大多数 ASCII 字符可以简单地由字符本身表示.

例如,密钥序列 FRED 可以用FRED"表示.

控制键、功能键等特殊键用{大括号}编码

<前>……………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………………:键/字符:SendKey:描述::………………………………………………………………………………………………………………………………………………………………………………………………………………::~ : {~} : 发送波浪号 (~) ::!: {!} : 发送感叹号 (!) :: ^ : {^} : 发送插入符号 (^) ::+ : {+} : 发送加号 (+) :: Backspace : {BACKSPACE} or {BKSP} or {BS} : 发送 Backspace 按键:: Break : {BREAK} : 发送 Break 按键::Caps Lock :{CAPSLOCK} :按下 Caps Lock 键(打开或关闭):: 清除 : {CLEAR} : 清除字段 :: 删除 : {DELETE} 或 {DEL} : 发送删除键::插入 :{INSERT} 或 {INS} :发送插入击键::光标控制箭头:{LEFT}/{RIGHT}/{UP}/{DOWN} :发送左/右/上/下箭头:: End : {END} : 发送 End 击键 :: Enter : {ENTER} 或 ~ : 发送 Enter 按键:: Escape : {ESCAPE} : 发送 Esc 键击::F1 到 F16 :{F1} 到 {F16} :发送功能键击:: 帮助 : {HELP} : 发送帮助按键 :: Home : {HOME} : 发送 Home 按键:: Page Down : {PGDN} : 发送 Page Down 击键 :: Page Up : {PGUP} : 发送 Page Up 击键 :: Numlock : {NUMLOCK} : 发送一个 Num Lock 按键::滚动锁定 :{SCROLLLOCK} :按下滚动锁定键(打开或关闭):: 打印屏幕 : {PRTSC} : 发送打印屏幕按键 ::………………………………………………………………………………………………………………………………………………………………………………………………………………:

<块引用>

要使用 SHIFTCTRLALT 键的任意组合指定键,请按如下方式在它们之前:

对于带有 + 的 SHIFT 前缀对于带有 ^ 的 CTRL 前缀对于带有 % 的 ALT 前缀

I'm aware of the probably most common form:

set wShell = createObject("wscript.shell")
wShell.sendKeys ":){ENTER}"

this uncommon and limited way:

Set ShellApp = CreateObject("Shell.Application")
ShellApp.WindowSwitcher

we can hackishly use sleep if we want a sequence of keys which depends on other events:

WScript.sleep 987
wShell.sendKeys "foo{!}~"
WScript.sleep 789
wShell.sendKeys "^a^c"

and we can't really keep a key pressed but we can repeat it many times:

wShell.sendKeys "{LEFT 42}"

now... am I missing something?

解决方案

yeah, I'm probably missing something.

meanwhile I figured this useful tabled reference might still be useful if shamelessly adapted here:

Most ASCII characters can be represented simply by the character itself.

E.g, the key sequence FRED can be represented by "FRED".

Special keys such as the control keys, function keys etc are encoded with {braces}

................................................................................................................
:     Key/Character     :                SendKey                :                 Description                  :
:.......................:.......................................:..............................................:
: ~                     : {~}                                   : Send a tilde (~)                             :
: !                     : {!}                                   : Send an exclamation point (!)                :
: ^                     : {^}                                   : Send a caret (^)                             :
: +                     : {+}                                   : Send a plus sign (+)                         :
: Backspace             : {BACKSPACE} or {BKSP} or {BS}         : Send a Backspace keystroke                   :
: Break                 : {BREAK}                               : Send a Break keystroke                       :
: Caps Lock             : {CAPSLOCK}                            : Press the Caps Lock Key (toggle on or off)   :
: Clear                 : {CLEAR}                               : Clear the field                              :
: Delete                : {DELETE} or {DEL}                     : Send a Delete keystroke                      :
: Insert                : {INSERT} or {INS}                     : Send an Insert keystroke                     :
: Cursor control arrows : {LEFT} / {RIGHT} / {UP} / {DOWN}      : Send a Left/Right/Up/Down Arrow              :
: End                   : {END}                                 : Send an End keystroke                        :
: Enter                 : {ENTER} or ~                          : Send an Enter keystroke                      :
: Escape                : {ESCAPE}                              : Send an Esc keystroke                        :
: F1 through F16        : {F1} through {F16}                    : Send a Function keystroke                    :
: Help                  : {HELP}                                : Send a Help keystroke                        :
: Home                  : {HOME}                                : Send a Home keystroke                        :
: Page Down             : {PGDN}                                : Send a Page Down keystroke                   :
: Page Up               : {PGUP}                                : Send a Page Up keystroke                     :
: Numlock               : {NUMLOCK}                             : Send a Num Lock keystroke                    :
: Scroll lock           : {SCROLLLOCK}                          : Press the Scroll lock Key (toggle on or off) :
: Print Screen          : {PRTSC}                               : Send a Print Screen keystroke                :
:.......................:.......................................:..............................................:

To specify keys with any combination of SHIFT, CTRL and ALT keys, precede them as following:

For SHIFT prefix with +
For CTRL  prefix with ^
For ALT   prefix with %

这篇关于我们如何使用 vbs 模拟键盘键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆