Created
March 1, 2018 21:15
-
-
Save heolin/e347733217018fbc3a1732063d550d17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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