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不是强制性的,您可以提出任何程序化解决方案。
答案 0 :(得分:0)
需要扫描代码(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)
答案 1 :(得分:0)
我认为这是Windows中的一个错误。这是一个例子,在记事本中“%”起作用,在CMD中则不起作用:
' 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