Hotkey working
This commit is contained in:
parent
accc5eb3b5
commit
7043313f60
10
macro.py
10
macro.py
|
@ -10,7 +10,7 @@ import os
|
|||
|
||||
mouseControl = mouse.Controller()
|
||||
keyboardControl = keyboard.Controller()
|
||||
special_keys = {"Key.shift": Key.shift, "Key.tab": Key.tab, "Key.caps_lock": Key.caps_lock, "Key.ctrl": Key.ctrl, "Key.ctrl_l": Key.ctrl_l, "Key.alt": Key.alt, "Key.cmd": Key.cmd, "Key.cmd_r": Key.cmd_r, "Key.alt_r": Key.alt_r, "Key.ctrl_r": Key.ctrl_r, "Key.shift_r": Key.shift_r, "Key.enter": Key.enter, "Key.backspace": Key.backspace, "Key.f19": Key.f19, "Key.f18": Key.f18, "Key.f17": Key.f17, "Key.f16": Key.f16, "Key.f15": Key.f15, "Key.f14": Key.f14, "Key.f13": Key.f13, "Key.media_volume_up": Key.media_volume_up, "Key.media_volume_down": Key.media_volume_down, "Key.media_volume_mute": Key.media_volume_mute, "Key.media_play_pause": Key.media_play_pause, "Key.f6": Key.f6, "Key.f5": Key.f5, "Key.right": Key.right, "Key.down": Key.down, "Key.left": Key.left, "Key.up": Key.up, "Key.page_up": Key.page_up, "Key.page_down": Key.page_down, "Key.home": Key.home, "Key.end": Key.end, "Key.delete": Key.delete, "Key.space": Key.space}
|
||||
special_keys = {"Key.esc": Key.esc, "Key.shift": Key.shift, "Key.tab": Key.tab, "Key.caps_lock": Key.caps_lock, "Key.ctrl": Key.ctrl, "Key.ctrl_l": Key.ctrl_l, "Key.alt": Key.alt, "Key.cmd": Key.cmd, "Key.cmd_r": Key.cmd_r, "Key.alt_r": Key.alt_r, "Key.ctrl_r": Key.ctrl_r, "Key.shift_r": Key.shift_r, "Key.enter": Key.enter, "Key.backspace": Key.backspace, "Key.f19": Key.f19, "Key.f18": Key.f18, "Key.f17": Key.f17, "Key.f16": Key.f16, "Key.f15": Key.f15, "Key.f14": Key.f14, "Key.f13": Key.f13, "Key.media_volume_up": Key.media_volume_up, "Key.media_volume_down": Key.media_volume_down, "Key.media_volume_mute": Key.media_volume_mute, "Key.media_play_pause": Key.media_play_pause, "Key.f6": Key.f6, "Key.f5": Key.f5, "Key.right": Key.right, "Key.down": Key.down, "Key.left": Key.left, "Key.up": Key.up, "Key.page_up": Key.page_up, "Key.page_down": Key.page_down, "Key.home": Key.home, "Key.end": Key.end, "Key.delete": Key.delete, "Key.space": Key.space}
|
||||
|
||||
record = False
|
||||
playback = False
|
||||
|
@ -30,8 +30,10 @@ def startRecord():
|
|||
keyboard_listener.start()
|
||||
|
||||
def stopRecord():
|
||||
global macroEvents
|
||||
mouse_listener.stop()
|
||||
keyboard_listener.stop()
|
||||
macroEvents["events"].pop()
|
||||
print('record stopped')
|
||||
|
||||
|
||||
|
@ -144,11 +146,11 @@ def playRec():
|
|||
|
||||
while True:
|
||||
if record == False:
|
||||
if is_pressed('1'):
|
||||
if is_pressed('è'):
|
||||
print("pressed 1")
|
||||
startRecord()
|
||||
if playback == False:
|
||||
if is_pressed('3'):
|
||||
if is_pressed('à'):
|
||||
playRec()
|
||||
|
||||
if (record == False and playback == False):
|
||||
|
@ -158,7 +160,7 @@ while True:
|
|||
saveMacro()
|
||||
|
||||
if record == True:
|
||||
if is_pressed('2'):
|
||||
if is_pressed('escape'):
|
||||
print(read_key())
|
||||
print("pressed 2")
|
||||
record = False
|
||||
|
|
89
software.py
89
software.py
|
@ -2,12 +2,49 @@ import threading
|
|||
from tkinter import *
|
||||
from tkinter.ttk import *
|
||||
from pynput import keyboard
|
||||
from keyboard import is_pressed
|
||||
import subprocess
|
||||
import atexit
|
||||
import time
|
||||
|
||||
|
||||
playback2 = False
|
||||
record2 = False
|
||||
keyboardControl = keyboard.Controller()
|
||||
|
||||
|
||||
|
||||
def on_release(key):
|
||||
global record2, playback2, recordBtn, lengthOfRecord
|
||||
try:
|
||||
if key.char == 'è':
|
||||
if record2 == False:
|
||||
startRecordingAndChangeImg(False)
|
||||
if key.char == 'à':
|
||||
if (record2 == False and playback2 == False):
|
||||
replay(False)
|
||||
except AttributeError:
|
||||
if key == keyboard.Key.esc:
|
||||
if record2 == True:
|
||||
stopRecordingAndChangeImg(False)
|
||||
|
||||
|
||||
# def key_released(e):
|
||||
# global record2, playback2
|
||||
#
|
||||
# if e.keysym == 'Escape':
|
||||
# if record2 == True:
|
||||
# stopRecordingAndChangeImg(False)
|
||||
#
|
||||
# if e.char == 'è':
|
||||
# if (record2 == False and playback2 == False):
|
||||
# startRecordingAndChangeImg(False)
|
||||
# #
|
||||
# if e.char == 'à':
|
||||
# if (record2 == False and playback2 == False):
|
||||
# replay(False)
|
||||
|
||||
|
||||
def cleanup():
|
||||
if 'macro_process' in globals():
|
||||
macro_process.terminate()
|
||||
|
@ -27,33 +64,46 @@ my_menu = Menu(window)
|
|||
window.config(menu=my_menu)
|
||||
|
||||
|
||||
def startRecordingAndChangeImg():
|
||||
global stopBtn
|
||||
global lenghtOfRecord
|
||||
keyboardControl.press('1')
|
||||
keyboardControl.release('1')
|
||||
lenghtOfRecord = time.time()
|
||||
recordBtn.configure(image=stopImg, command=stopRecordingAndChangeImg)
|
||||
def startRecordingAndChangeImg(pressKey=True):
|
||||
global stopBtn, lengthOfRecord, record2, playback2
|
||||
if playback2 == False:
|
||||
if pressKey:
|
||||
keyboardControl.press('è')
|
||||
keyboardControl.release('è')
|
||||
lengthOfRecord = time.time()
|
||||
recordBtn.configure(image=stopImg, command=stopRecordingAndChangeImg)
|
||||
record2 = True
|
||||
print('function start callled')
|
||||
|
||||
|
||||
def stopRecordingAndChangeImg():
|
||||
global recordBtn
|
||||
global lenghtOfRecord
|
||||
keyboardControl.press('2')
|
||||
keyboardControl.release('2')
|
||||
lenghtOfRecord = (time.time() - lenghtOfRecord) + 1
|
||||
def stopRecordingAndChangeImg(pressKey=True):
|
||||
global recordBtn, lengthOfRecord, record2
|
||||
if pressKey:
|
||||
keyboardControl.press(keyboard.Key.esc)
|
||||
keyboardControl.release(keyboard.Key.esc)
|
||||
print(time.time() - lengthOfRecord)
|
||||
lengthOfRecord = (time.time() - lengthOfRecord) + 2
|
||||
recordBtn.configure(image=recordImg, command=startRecordingAndChangeImg)
|
||||
playBtn.configure(state=NORMAL)
|
||||
print('record stoppé')
|
||||
record2 = False
|
||||
|
||||
def replay():
|
||||
def replay(pressKey=True):
|
||||
global playback2, recordBtn
|
||||
playback2 = True
|
||||
if pressKey:
|
||||
keyboardControl.press('à')
|
||||
keyboardControl.release('à')
|
||||
recordBtn.configure(state=DISABLED)
|
||||
keyboardControl.press('3')
|
||||
keyboardControl.release('3')
|
||||
threading.Thread(target=buttonDisabledToEnable).start()
|
||||
|
||||
def buttonDisabledToEnable():
|
||||
time.sleep(lenghtOfRecord)
|
||||
global playback2, lengthOfRecord
|
||||
time.sleep(lengthOfRecord)
|
||||
recordBtn.configure(state=NORMAL)
|
||||
playback2 = False
|
||||
|
||||
|
||||
|
||||
|
||||
# Menu Bar
|
||||
|
@ -78,6 +128,9 @@ recordBtn.pack(side=RIGHT, padx=50)
|
|||
# Stop Button
|
||||
stopImg = PhotoImage(file=r"assets/button/stop.png")
|
||||
|
||||
# window.bind('<KeyRelease>',key_released )
|
||||
|
||||
keyboardListener = keyboard.Listener(on_release=on_release)
|
||||
keyboardListener.start()
|
||||
|
||||
window.mainloop()
|
||||
window.mainloop()
|
Loading…
Reference in New Issue