0

尝试通过向应用程序发送击键来自动生成报告。我可以将应用程序向前推进,但它会忽略所有 SendKeys 命令。问题是什么?接下来我应该尝试什么?这是我的代码:

    Const App_Title = "AccountRight Plus"  ' Window title
    Dim Wsh, win_title
    ' Create the WshShell object, which Run and AppActivate require.
    Set Wsh = WScript.CreateObject("WScript.Shell")
    Wsh.AppActivate App_Title
    WScript.Sleep 800
    Wsh.SendKeys "^i"
    WScript.Sleep 800
    Wsh.SendKeys "{TAB}"
    WScript.Sleep 800
    Wsh.SendKeys "{TAB}"
4

1 回答 1

0

Probably you have confusion with the caps lock key and stroke "^i". Just hypothesis anyway. If this is not the case then at least not judge me.

So I made a code that I can test here, to explain what I mean.

Set Wsh = WScript.CreateObject("WScript.Shell")
Wsh.Run "notepad"
Wsh.AppActivate "Untitled - Notepad"
WScript.Sleep 100
Wsh.SendKeys "111..."
WScript.Sleep 100
Wsh.SendKeys "^a" ' (ctrl+a) Select All command

If by chance the caps lock key is off, above code will select all text, but stroke "^a" (or even "^(a)") will fail if caps lock is on. And contrariwise, if you use "^A" will fail with caps lock off.

There no way to get the state of caps lock (or other keys) in VBScript, but I found 2 work arounds, call them cheats if you like :)

  1. A bit weird way to go, is to duplicate your SendKeys command.

    Wsh.SendKeys "^a" : Wsh.SendKeys "^a"

  2. To send stroke to caps lock in advance.

    Wsh.SendKeys "{CAPSLOCK}" : Wsh.SendKeys "^a"

于 2013-01-21T11:45:59.557 回答