windows 如何将一些字符串粘贴到 Python 中的活动窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3048307/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:39:38  来源:igfitidea点击:

How can I paste some string to the active window in Python?

pythonwindows

提问by Bruno 'Shady'

Possible Duplicate:
How do I copy a string to the clipboard on Windows using Python?

可能的重复:
如何使用 Python 将字符串复制到 Windows 上的剪贴板?

Can someone make me an example or explain to me how can I paste something to the active window with Python?

有人可以给我举个例子或向我解释如何使用 Python 将某些内容粘贴到活动窗口吗?

I've edited because I didn't know that paste to the clipboard doesnt paste to the active window...

我进行了编辑,因为我不知道粘贴到剪贴板不会粘贴到活动窗口...

回答by jma

since you haven't accepted the duplicate as an answer may i suggest:

由于您尚未接受重复作为答案,我建议:

import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys('keys to send to active window...')

from:

从:

here

这里

and if you need to find out about keys like Backspace go to

如果您需要了解 Backspace 之类的键,请访问

here

这里