有没有一种模拟Windows alt-tabbing的方法?

问题描述

@H_404_0@我想创建一个程序,将选项卡替换为例如不和,然后向用户输入消息。

import time
from pynput.keyboard import Key,Controller
keyboard=Controller()
keyboard.press(Key.alt_l)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
keyboard.release(Key.alt_l)
time.sleep(1)
keyboard.type('this is a test message.')
keyboard.press(Key.enter)
@H_404_0@这就是我目前要模拟alt制表的功能,但是可以将alt制表符转换为特定程序吗?

解决方法

您可以使用pywinauto实现类似的功能,该模块允许您以pythonic方式与程序GUI进行交互。 示例:

from pywinauto.application import Application
app = Application().start("notepad.exe")

app.UntitledNotepad.menu_select("File->New")

您可以在其文档here

中了解更多有关pywinauto及其功能的信息。