Hola usuario de nuestro sitio web, tenemos la solución a lo que necesitas, deslízate y la obtendrás aquí.
Ejemplo 1: cómo ejecutar key combinaciones con teclado python lib
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')# Press keys with hex, code in: https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes
keyboard.press(KeyCode.from_vk(0x5C))
keyboard.press(KeyCode.from_vk(0x27))
keyboard.release(KeyCode.from_vk(0x27))
keyboard.release(KeyCode.from_vk(0x5C))# Type 'Hello World' using the shortcut type method
keyboard.type('Hello World')
Ejemplo 2: pulsación del teclado de Python
import keyboard # using module keyboardimport time
stop =Falsedefonkeypress(event):global stop
if event.name =='q':
stop =True# ---------> hook event handler
keyboard.on_press(onkeypress)# --------->whileTrue:# making a looptry:# used try so that if user pressed other than the given key error will not be shownprint("sleeping")
time.sleep(5)print("slept")if stop:# if key 'q' is pressed print('You Pressed A Key!')break# finishing the loopexcept:print("#######")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')
Ten en cuenta compartir esta sección si te ayudó.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)