Created
April 26, 2018 08:51
-
-
Save cascad-s/2da663d4d5b1e73cfd9389c27a38ddf0 to your computer and use it in GitHub Desktop.
tool_for_monotonic_copy
This file contains 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 pprint import pprint | |
from time import sleep | |
import keyboard | |
import pyperclip | |
def get_from_clipboard(): | |
return pyperclip.paste() | |
def paste_to_clipboard(data): | |
pyperclip.copy(data) | |
START = "shift+f1" | |
STOP = "shift+f9" | |
DESTROY = "shift+f12" | |
# SAVE = "shift+s" | |
SAVE = "ctrl+c" | |
SET_DATA = "shift+1" | |
SET_VIDEO = "shift+2" | |
SET_PHOTO = "shift+3" | |
class States: | |
def __init__(self): | |
self.runned = False | |
self.type = None | |
self.storage = [] | |
def set_type(self, dtype): | |
if self.runned: | |
print("set {}".format(dtype)) | |
self.type = dtype | |
else: | |
print("not runned") | |
def stop(self): | |
print("stopped") | |
self.remove_listeners() | |
self.runned = False | |
def start(self): | |
print("runned") | |
self.add_listeners() | |
self.runned = True | |
def save(self): | |
sleep(0.1) # os saved in clipboard | |
if self.runned: | |
if self.type: | |
raw = get_from_clipboard() | |
to_save = (self.type, raw) | |
self.storage.append(to_save) | |
print("saved -> {}".format(to_save)) | |
self.type = None | |
else: | |
print("not typing") | |
else: | |
print("not runned") | |
def add_listeners(self): | |
if not self.runned: | |
keyboard.add_hotkey(SAVE, self.save) # args=('triggered', 'num 0') | |
keyboard.add_hotkey(SET_DATA, self.set_type, args=("DATA",)) | |
keyboard.add_hotkey(SET_PHOTO, self.set_type, args=("PHOTO",)) | |
keyboard.add_hotkey(SET_VIDEO, self.set_type, args=("VIDEO",)) | |
def remove_listeners(self): | |
if self.runned: | |
keyboard.remove_hotkey(SAVE) | |
keyboard.remove_hotkey(SET_DATA) | |
keyboard.remove_hotkey(SET_PHOTO) | |
keyboard.remove_hotkey(SET_VIDEO) | |
if __name__ == "__main__": | |
states = States() | |
keyboard.add_hotkey(START, states.start) | |
keyboard.add_hotkey(STOP, states.stop) | |
states.start() | |
keyboard.wait(DESTROY) | |
pprint(states.storage) | |
print("destroy") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment