代码之家  ›  专栏  ›  技术社区  ›  leeand00

如何使用wscript.shell替换+制表符?

  •  0
  • leeand00  · 技术社区  · 7 年前

    可以用吗 wscript.shell 发送Alt+选项卡?

    $wshell = New-Object -ComObject wscript.shell;
    $wshell.SendKeys('\t')
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   StephenP    7 年前

    我用 System.Windows.Forms.SendKeys 相反。

    Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.SendKeys]::SendWait('%{TAB}')
    

    不知道为什么,但wscript.shell不适用于%tab。

        2
  •  0
  •   postanote    7 年前

    这是因为它不需要使用%或\t。

    例子:

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "notepad", 9 
    
    ' Give Notepad time to load
    WScript.Sleep 500 
    
    Dim Msg: Msg = "Hello, World!"
    
    ' Type in One Character at a time
    For i = 1 To Len(Msg)
        WScript.Sleep 200
        WshShell.SendKeys Mid(Msg, i, 1)
    Next
    
    WshShell.SendKeys "{ENTER}"
    WshShell.SendKeys "^{HOME}"
    WshShell.SendKeys "{TAB}"
    

    但既然我们都喜欢PowerShell,那么Stephenp给你的就是PowerShell方式。