How to use keyboard library?

2

How to use the keyboard to perform an activity if a key is pressed? In my searches, I could not find any examples in this template:

import keyboard

b = 0
if keyboard.press('b'): #sei que o certo não é utilizar o press, mas, o que boto no lugar?
    b = 1
    
asked by anonymous 18.11.2018 / 01:05

1 answer

1

You can use an Automation Lib with Python, for example:
pyautogui (Python2) - link

pywinauto (Python3) - link

p>
import pyautogui

pyautogui.press('enter')

In python3 you could do this:

from pywinauto.keyboard import SendKeys, KeySequenceError

try:
    SendKeys({ESC})
except Exception as exception:
    print str(exception)
    
18.11.2018 / 04:46