Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3915

Python • Re: I got a massive error and have no idea what it means

$
0
0
I've been able to get your program to work but there looks like there could be conflicts between 'keyboard' and 'pyautogui'. Sorry I wasn't able to replicate your problem

I took your code and commented out the 'pyautogui' calls. Everything worked running from SUDO.

I then had a look at 'pyautogui' at https://pyautogui.readthedocs.io/en/latest/index.html. It seems this is used to 'drive' a GUI. I wasn't able to find any reference of using 'pyautogui' to read the keyboard. See https://pyautogui.readthedocs.io/en/lat ... t=keyboard. I would research the use of 'keyboard' and 'pyautogui'. There may be conflicts.

When I got your full program running, I noticed that 'while not keyboard.is_pressed("esc")' no longer worked. I added a 'print(keyboard.read_key())' so I can see the keys pressed. In order to stop the program I had to close it from the task bar. I had to change the 'esc' test. Another suggestion in a conflict between these two libraries.

In order to see if the error might have been when two instances of the program running both grabbing the keyboard, I ran it from 2 separate terminal sessions. Interesting enough both report the keyboard keys.

I also had to use 'sudo pip install keyboard pyautogui'. Here's the modified program

Code:

import timeimport pyautoguiimport keyboard# Get initial mouse positioninitial_x, initial_y = pyautogui.position()while True:# Click at the initial mouse positionchar=keyboard.read_key()if char == "esc": breakprint(keyboard.read_key())pyautogui.click(x=initial_x, y=initial_y)time.sleep(0.1) # Adjust the delay between clicks if neededprint("Stopped clicking (Esc key pressed).")

Statistics: Posted by DS256 — Wed May 15, 2024 11:23 pm



Viewing all articles
Browse latest Browse all 3915

Trending Articles