Agradecemos tu ayuda para extender nuestras reseñas acerca de las ciencias informáticas.
Ejemplo 1: tipo de Python en el teclado
pip install keyboard
import keyboard
keyboard.press_and_release('shift+s, space')
keyboard.write('The quick brown fox jumps over the lazy dog.')
keyboard.add_hotkey('ctrl+shift+a',print, args=('triggered','hotkey'))# Press PAGE UP then PAGE DOWN to type "foobar".
keyboard.add_hotkey('page up, page down',lambda: keyboard.write('foobar'))# Blocks until you press esc.
keyboard.wait('esc')# Record events until 'esc' is pressed.
recorded = keyboard.record(until='esc')# Then replay back at three times the speed.
keyboard.play(recorded, speed_factor=3)# Type @@ then press space to replace with abbreviation.
keyboard.add_abbreviation('@@','[email protected]')# Block forever, like `while True`.
keyboard.wait()
Ejemplo 2: módulo para leer teclado
import keyboard # using module keyboardwhileTrue:# making a looptry:# used try so that if user pressed other than the given key error will not be shownif keyboard.is_pressed('q'):# if key 'q' is pressed print('You Pressed A Key!')break# finishing the loopexcept:break# if user pressed a key other than the given key the loop will break
Ejemplo 3: biblioteca de Python para controlar el teclado
from pynput.keyboard import Key, Controller
keyboard = Controller()# Press and release space
keyboard.press(Key.space)
keyboard.release(Key.space)# Type a lower case A; this will work even if no key on the# physical keyboard is labelled 'A'
keyboard.press('a')
keyboard.release('a')# Type two upper case As
keyboard.press('A')
keyboard.release('A')with keyboard.pressed(Key.shift):
keyboard.press('a')
keyboard.release('a')# Type 'Hello World' using the shortcut type method
keyboard.type('Hello World')
Te mostramos las reseñas y valoraciones de los lectores
Si posees alguna desconfianza o disposición de beneficiar nuestro tutorial eres capaz de escribir una ilustración y con deseo lo leeremos.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)