Jogim
Jogim

Reputation: 13

Prevent keystrokes

It is necessary to make sure that during a certain period of time they are not available for pressing a certain key, for example Space. So that during a break, user clicks are not displayed in any way in the input(). Please suggest a module or a complete solution. Example:

import time

time.sleep(5) # So that during this period of time nothing could be written.

enter = input()

Upvotes: 1

Views: 155

Answers (1)

HoneyPoop
HoneyPoop

Reputation: 513

welcome to SO! Your description is very vague, but assuming you want to prevent a specific keystroke from affecting your program for 5 seconds, this might just work:

import keyboard
import time

time_end = time.time() + 5
while time.time() < time_end:
    if keyboard.is_pressed('q'):
        pass

replace 'q' with the key you don't want to affect your program. Wherever "pass" is is what will happen if q is pressed within those seconds. I think q will still show up in your program when it's pressed, but wont affect any of your other functions unless you have threading. Sorry if this doesn't help, this is the only thing I could think of.

Upvotes: 1

Related Questions