Python keyboard module questions 2.0
Go to solution
Solved by Sauron,
5 minutes ago, stefanmz said:Yes but is there a keyboard command which if I press anything else on the keyboard, goes to else and doesn't fulfill the if
you can use is_pressed to check if a given combination is currently being pressed. this will just instantly fall through when you run the program since it's not blocking. you can use read_event or read_key to block the program until something is pressed, then use is_pressed to check that what is being pressed is the "correct" combination. Note that as soon as you press anything the program will stop waiting and it will give you no time to press keys in succession; you might want to add a small delay after the read_key call so you have time to press all the keys.
import keyboard import time keyboard.read_key() #block program until something is pressed time.sleep(1) #give user 1 second to press and hold all required keys if keyboard.is_pressed('8+9'): #ok if 8 and 9 are pressed at the same time print('ok') else: print('not ok')

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now