Checking if a specific key is being been pressed or not
Approach:
- Take user input
- Create a loop
- Use condition
- Print output
Here we are taking an input from a user and detecting that the user has entered the specified Alphanumerical(characters representing the numbers 0 – 9, the letters A – Z (both uppercase and lowercase), and some common symbols such as @ # * and &.) or not.
Python3
for _ in range ( 3 ): user_input = input ( " Please enter your lucky word or type 'END' to terminate loop: " ) if user_input = = "geek" : print ( "You are really a geek" ) break elif user_input = = "END" : break else : print ( "Try Again" ) |
Output:
How to detect if a specific key pressed using Python?
In this article, we will learn how can we detect if a specific key is pressed by the user or not. The whole Module is divided into 3 segments, The 1st segment deal with simple integers, 2nd Alphanumerical characters and In 3rd we will use a python module to detect a key.