我是Python的新手,并试图将键击的组合发送到在Windows 7下打开的应用程序。当我调用记事本时,我的脚本将完美地工作。 EXE为测试目的,它不与我正在尝试使用的实际应用程序。如何使用SendKeys将模拟键盘笔画发送到活动窗口
这是到目前为止我的代码:
import win32com.client
import time
import SendKeys
import os
from ctypes import *
shell = win32com.client.Dispatch("WScript.Shell")
os.startfile("C:\...exe")
time.sleep(5)
shell.SendKeys('%{F4}') # 'Alt+F4' to close the application again.
出于某种原因,应用程序不会关闭在反应脚本。当我在键盘上点击“Alt + F4”时,它会按预期关闭。关于可能发生在这里的任何想法?
欢迎任何帮助!请记住,我是新来的Python ;-)
PS:我已经验证了应用程序在活动窗口通过包括此代码段运行:
import win32ui
wnd = win32ui.GetForegroundWindow()
print wnd.GetWindowText()
哪些是您的具体要求?你为什么使用Python?它看起来好像你已经把自己涂在了一个角落里。 – Apalala 2011-01-09 01:17:43