get keystroke python code example
Example 1: Presskeys in python
import pyautogui
# Holds down the alt key
pyautogui.keyDown("alt")
# Presses the tab key once
pyautogui.press("tab")
# Lets go of the alt key
pyautogui.keyUp("alt")
Example 2: python check key press
import keyboard
# if key 'a' is pressed
if keyboard.is_pressed('a'):
print('a key has ben pressed')