如何在 Windows 版 Python 中禁用和启用键盘输入?

问题描述 投票:0回答:1

嗨,我目前正在为《Valorant》开发一个触发机器人(我不想作弊,我只是想学习 python 编码并将其与像素检测和输入制作相结合),并想问我如何禁用键盘输入并在其他任务。像这样的东西:

Import mouse
Import keyboard

//diable keyboard here
Mouse.click(„left“)
//enable keyboard here

这只是程序的一部分,如果需要其余部分,我当然可以添加它。

我尝试寻找一些相关内容,但对我来说没有用。 我将不胜感激的帮助。 抱歉我的英语可能不好。

python input keyboard
1个回答
0
投票

您可以使用 pyautogui 库暂时阻止键盘输入。然后,完成所需的任务后,您可以再次启用它。

import pyautogui

# Disable keyboard input
pyautogui.FAILSAFE = False

# Perform your task
pyautogui.click('left')

# Enable keyboard input
pyautogui.FAILSAFE = True
© www.soinside.com 2019 - 2024. All rights reserved.