如何将Alt +空格发送到控制台窗口?

import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("Command Prompt") shell.SendKeys("%{ }") # This #shell.SendKeys("% ") # and this #shell.SendKeys("%( )") # and this is not working 

WScript不是强制性的,你可以提出任何程序化的解决scheme。

扫描码(56和57)是必需的:

 from win32api import * from win32con import * keybd_event(VK_LMENU, 56, 0, 0) keybd_event(VK_SPACE, 57, 0, 0) keybd_event(VK_SPACE, 57, KEYEVENTF_KEYUP, 0) keybd_event(VK_LMENU, 56, KEYEVENTF_KEYUP, 0) 

我认为这是在Windows中的错误。 这里是一个例子,在记事本中,“%”起作用,在CMD中它不起作用:

     SendKeys.vbs示例脚本
     'VBScript发送键盘笔画到命令提示符和记事本
     '------------------------------------------------- -------”
    选项显式

     Dim objShell,WshShell
     set objShell = CreateObject(“WScript.Shell”)
     objShell.Run( “CMD”)
     objShell.AppActivate(“命令提示符”)
     WScript.Sleep 500
     objShell.SendKeys“记事本〜”
     WScript.Sleep 500
     ' 有用
     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
     '不行
     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
     SendKeys示例脚本结束