Beat_The_Boxer26
Beat_The_Boxer26

Reputation: 1

Keyboard Module in python not working on mac

When ever I run

import keyboard if keyboard.is_pressed('q'):
    while True:
        print("bean") 
else:
    quit()

I get this error:

   Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner

Could someone please help could this possibly be the fact that im on a Mac or am I just dumb

Upvotes: 0

Views: 514

Answers (1)

Michael F
Michael F

Reputation: 66

Problem 1:

Your import and if should not be on the same line. Import then begin if statement

Problem 2:

You have an infinite loop created by your while True with no exit. I think your intention is probably to print “bean” as long as q is pressed. If this is the case your if probably needs to be inside your while loop.

You are bound to have further problems after working those out but isn’t that point and enjoyment of programming?

Upvotes: 1

Related Questions