Fahim
Fahim

Reputation: 348

How to get keypress and make decisions in pynput

I'm trying to make a script where the script will wait for a keypress, and if the keypress is 'enter', then it will start executing the rest of the code. Otherwise, it'll again ask for a keypress.

I'm trying to use pynput. But the problem is, with the given example in the documentation, it just keep taking the inputs and shows the inputs. But I'm unable to make conditions on each input and get out of the loop. I have to press escape by myself.

Upvotes: 0

Views: 96

Answers (1)

moqin
moqin

Reputation: 74

In fact ,you don't have to worry about catching a 'Enter'.Think about it in a different way,if there is only an 'Enter' is input ,that means user didn't input any word but just an "Enter". So,we can use these codes below.

inp=input("waiting for an 'Enter'")
while inp !="":
    inp=input("waiting for an 'Enter'")
print("Now it executes the rest")

Upvotes: 1

Related Questions