How do I detect a keypress event with PyAutoGUI?

Mi Tavares picture Mi Tavares · Nov 19, 2018 · Viewed 10.8k times · Source

How do I use PyAutoGUI to detect a keypress event? In my research, I could not make an example in this model:

import pyautogui

num = 0
if pyautogui.press('b'): # I know the right thing is not to use the press, but, what do I put in place?
    num = 1

Answer

Al Sweigart picture Al Sweigart · Nov 27, 2018

Detecting keystrokes isn't possible in PyAutoGUI. You might want to try the Pynput module instead: https://pypi.org/project/pynput/