Answers for "check key pressed"

10

How to detect key presses

import keyboard  # using module keyboard
while True:  # making a loop
    try:  # used try so that if user pressed other than the given key error will not be shown
        if keyboard.is_pressed('q'):  # if key 'q' is pressed 
            print('You Pressed A Key!')
            break  # finishing the loop
    except:
        break  # if user pressed a key other than the given key the loop will break
Posted by: Guest on April-10-2020
0

check key is pressed java

if (evt. getKeyCode() == KeyEvent. VK_SHIFT)
Posted by: Guest on August-06-2020
0

if keyboard.is_pressed

# keyboard module
# windows: pip install keyboard
# mac: pip3 install keyboard

import keyboard as k
if k.is_pressed("a"):
  # if the a key is pressed by the user
  print("You have pressed the key 'a'")
Posted by: Guest on February-01-2021

Code answers related to "check key pressed"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language