Answers for "python keyboard.is_pressed in while"

7

python pressed key

# pip3 install pynput

from pynput.keyboard import Key, Listener


def show(key):

    pressed_key = str(key).replace("'", "")
    print(" key: ", pressed_key)

    if key == Key.esc:
        # Stop listener
        return False


# Listener
with Listener(on_press=show) as listener:
    listener.join()
Posted by: Guest on May-28-2021
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

Python Answers by Framework

Browse Popular Code Answers by Language