-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (47 loc) · 2.43 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from pynput import keyboard
from pynput.keyboard import Key, Controller
from resources.phrase_fetcher import *
import pyperclip
import configparser
import sys
import pyautogui
import time
import os
phrase_buffer = ''
fence = True
configuration = configparser.ConfigParser()
if 'config.ini' in os.listdir('.'):
configuration.read('config.ini', encoding='utf-8')
else:
pyautogui.alert('Failed to detect configuration file. Generating new one with default settings', title="TextMotes")
configuration['CONFIGURATION'] = {'updown': '🙃', 'heart': '❤', 'smile': '🙂', 'proud': '😁', 'wink': '😉', 'angel': '😇', 'think': '🤔', 'throw': '🤮', 'cowboy': '🤠', 'like': '👍', 'sleep': '😴', 'fright': '😬', 'shh': '🤫', 'faceless': '😶', 'swag': '😎', 'susp': '🧐', 'tear': '😢', 'sad': '😕', 'angry': '😡', 'skull': '💀', 'love': '😍', 'tong': '😛', 'cry': '😭', 'party': '🥳'}
with open('config.ini', 'w', encoding='utf-8') as config_file:
configuration.write(config_file)
if 'quit' in configuration['CONFIGURATION'].keys() or 'restart' in configuration['CONFIGURATION'].keys() or 'emotes' in configuration['CONFIGURATION'].keys():
pyautogui.alert('You named an emote with restricted phrase. Restricted phrases are:\n- quit\n- restart\n-emotes', title='TextMotes - shutting down')
sys.exit(0)
def on_press(key):
global phrase_buffer, fence
if str(key) != 'Key.space':
if str(key)[:4] != 'Key.':
if str(key).replace("'", '') == ';' and fence == True:
fence = False
elif str(key).replace("'", '') == ';' and fence == False:
fetch_phrase(phrase_buffer, configuration)
phrase_buffer, fence = '', True
elif fence == False:
phrase_buffer += str(key).replace("'", '')
else:
phrase_buffer = ''
elif str(key) != 'Key.shift':
if str(key) == 'Key.backspace' and fence == False:
phrase_buffer = phrase_buffer[:-1]
else:
phrase_buffer, fence = '', True
else:
phrase_buffer, fence = '', True
pyautogui.alert('PROGRAM S T A R T E D\n\nType ;quit; anywhere to exit the program in any moment.', title='TextMotes')
with keyboard.Listener(on_press=on_press) as listener:
listener.join()
listener = keyboard.Listener(on_press=on_press)
listener.start()