How to send Alt+space to console window?

前端 未结 2 515
萌比男神i
萌比男神i 2021-01-23 21:24
import win32com.client
shell = win32com.client.Dispatch(\"WScript.Shell\")
shell.AppActivate(\"Command Prompt\")
shell.SendKeys(\"%{ }\")               # This
#shell.Sen         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 21:53

    I think it is a bug in windows. Here is an example where in notepad the "% " works and in CMD it does not:

        ' SendKeys.vbs  Example Script
        ' VBScript to send keyboard strokes to command prompt and notepad
        ' --------------------------------------------------------'
        Option Explicit
    
        Dim objShell, WshShell
        set objShell = CreateObject("WScript.Shell")
        objShell.Run("cmd")
        objShell.AppActivate("Command Prompt")
        WScript.Sleep 500
        objShell.SendKeys "notepad~"
        WScript.Sleep 500
        ' It works
        objShell.SendKeys "% x"
        WScript.Sleep 200
        objShell.SendKeys "% r"
        WScript.Sleep 200
        objShell.SendKeys "%v"
        WScript.Sleep 200
        objShell.SendKeys "s"
        WScript.Sleep 200
        objShell.SendKeys "Algo{Enter}"
        WScript.Sleep 500
        objShell.SendKeys "%{TAB}"
        WScript.Sleep 500
        objShell.SendKeys "dir~"
        WScript.Sleep 500
        'Does not work
        objShell.SendKeys "% es"
        WScript.Sleep 3500
        objShell.SendKeys "{BACKSPACE}{BACKSPACE}Exit~"
        WScript.Sleep 3500
        objShell.SendKeys "%fx"
        WScript.Sleep 500
        objShell.SendKeys "{TAB}~"
    
        WScript.Quit
        '  End of SendKeys Example Script
    

提交回复
热议问题