python - 如何在特定应用程序上模拟按键
问题描述
我正在尝试设置一个为我做事的机器人,目前我必须在同一个窗口中才能工作。当机器人在该特定应用程序上运行时,是否可以更改我的窗口(例如使用谷歌浏览器)?
此外,如果您询问它的应用程序,它的 Runescape 只是一个旧游戏,我只是用它来了解有关 python 的更多信息。
我在网上找不到任何关于这样做的模块的信息。
from pynput.mouse import Button, Controller
from time import sleep
from random import randint, uniform
def move_mouse(next_pos):
sleep(uniform(0.1,0.2))
mouse.position = (randint(int(round(next_pos[0])), int(round(next_pos[2]))), randint(int(round(next_pos[1])), int(round(next_pos[3]))))
sleep(uniform(1,1.2))
mouse.click(Button.left, 1)
mouse = Controller()
print(mouse.position)
shaft = [ 1299.25, 590.48828125, 1315.6171875, 610.69921875]
box = [705.01171875, 600.671875, 957.640625, 616.37109375]
sleep(2)
while True:
move_mouse(shaft)
move_mouse(box)
sleep(71)
到目前为止,一切正常,我没有遇到任何错误。我所需要的只是让它点击一个特定的应用程序。
解决方案
推荐阅读
- python - 提取日志文件中的数据部分
- python - Why does `py.test --last-failed` skip many tests altough no tests had failed before?
- javascript - 使用行数(索引)动态追加和删除行
- python-3.x - 如何从 Pandas Dataframe 中获取字典
- javascript - 如何在力有向图中配置力参数以使图稳定
- python - 处理 dogpile.cache 装饰器异常
- swift - 如何向日期选择器添加时间
- reactjs - 有没有很好的 CLI 工具来开发、搭建和维护 React 应用程序?
- tally - 用于在计数中创建成本中心的 xml 格式
- c# - 如何将链接名称与链接 URL 进行比较(使用 C# 中的 Selenium webdriver)