Skip to content

Instantly share code, notes, and snippets.

@heolin
Created March 1, 2018 21:15
Show Gist options
  • Save heolin/e347733217018fbc3a1732063d550d17 to your computer and use it in GitHub Desktop.
Save heolin/e347733217018fbc3a1732063d550d17 to your computer and use it in GitHub Desktop.
from pynput import keyboard
import pyperclip
current = {"tags":[]}
def on_press(key):
global current
try: k = key.char # single-char keys
except: k = key.name # other keys
if key == keyboard.Key.esc: return False # stop listener
value = pyperclip.paste().split('\n')[0]
if k == "t":
if value not in current["tags"]:
current["tags"].append(value)
elif k == "q":
current["title"] = value
elif k == "w":
current["author"] = value
elif k == "e":
current["timestamp"] = value
elif k == "r":
current["source"] = value
if k in ['enter']:
print (current)
current = {"tags":[]}
lis = keyboard.Listener(on_press=on_press)
lis.start() # start to listen on a separate thread
lis.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment