在 Python 上激活 window 时自动按键和鼠标按下
Make auto key and mouse press on activate window on Python
我想在 Windows 的 Python 中编写一个应用程序来重复做一些工作。
例如,我需要将一些文件转换成其他类型。我在 Windows 中安装了一个软件来执行此操作。但是,该程序旨在逐个文件地执行此操作。现在我想自动完成。
因此,我需要编写一个软件来模拟激活时的按键windows。自动键盘上有很多代码,但它只适用于 运行 Python 脚本的终端。特别是,在我 运行 Python 脚本之后,我最小化终端,然后打开一些程序然后 Python 脚本将模拟按键 and/or 鼠标点击这个程序。
我发现很多程序都可以做热键之类的事情,按下热键后,它会模拟一些按键和鼠标。所以我觉得是可以的。
谁能给我一个解决方案?
谢谢。
这将帮助您实现自动化:
鼠标点击:
import pyautogui
pyautogui.click(1319, 45)
pyautogui.scroll(200)
pyautogui.hotkey("ctrlleft", "a")
对于键盘
import keyboard
# It writes the keys r, k and endofline
keyboard.press_and_release('shift + r, shift + k, \n')
keyboard.press_and_release('R, K')
# it blocks until esc is pressed
keyboard.wait('esc')
# It records all the keys until escape is pressed
rk = keyboard.record(until='Esc')
# It replay back the all keys
keyboard.play(rk, speed_factor=1)
我想在 Windows 的 Python 中编写一个应用程序来重复做一些工作。
例如,我需要将一些文件转换成其他类型。我在 Windows 中安装了一个软件来执行此操作。但是,该程序旨在逐个文件地执行此操作。现在我想自动完成。
因此,我需要编写一个软件来模拟激活时的按键windows。自动键盘上有很多代码,但它只适用于 运行 Python 脚本的终端。特别是,在我 运行 Python 脚本之后,我最小化终端,然后打开一些程序然后 Python 脚本将模拟按键 and/or 鼠标点击这个程序。
我发现很多程序都可以做热键之类的事情,按下热键后,它会模拟一些按键和鼠标。所以我觉得是可以的。
谁能给我一个解决方案?
谢谢。
这将帮助您实现自动化:
鼠标点击:
import pyautogui
pyautogui.click(1319, 45)
pyautogui.scroll(200)
pyautogui.hotkey("ctrlleft", "a")
对于键盘
import keyboard
# It writes the keys r, k and endofline
keyboard.press_and_release('shift + r, shift + k, \n')
keyboard.press_and_release('R, K')
# it blocks until esc is pressed
keyboard.wait('esc')
# It records all the keys until escape is pressed
rk = keyboard.record(until='Esc')
# It replay back the all keys
keyboard.play(rk, speed_factor=1)