迫于被远程桌面输命令疯狂重复按键折磨吐了写的,不过这样自动补全没了。好在不需要再用了
# test.py
import win32gui,win32api,win32con
import time
def send_to_cmd():
wndtitle = u"" # 窗口名称,可以spy++获取
wndclass = None
wnd = win32gui.FindWindow(wndclass, wndtitle)
win32api.keybd_event(13, 0, 0, 0)
win32gui.SetForegroundWindow(wnd)
win32api.SetCursorPos((1000, 200)) # 鼠标位置1
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 100, 100, 0, 0)
time.sleep(0.2)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 100, 100, 0, 0)
wndtitle = u"C:\WINDOWS\system32\cmd.exe - python test.py"
wndclass = None
wnd = win32gui.FindWindow(wndclass, wndtitle)
win32api.keybd_event(13, 0, 0, 0) #
win32gui.SetForegroundWindow(wnd)
win32api.SetCursorPos((100, 100)) # 鼠标位置2
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 100, 100, 0, 0)
time.sleep(0.2)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 100, 100, 0, 0)
def inputtxt(string):
import win32clipboard as w
w.OpenClipboard()
w.SetClipboardData(win32con.CF_UNICODETEXT,string)
w.CloseClipboard()
if __name__=='__main__':
while True:
s = input()
if s!='quitcmd':
inputtxt(s+'\n')
send_to_cmd()
else:
break