Skip to content

Commit eceb33c

Browse files
committed
Fixed hotkey inconsistencies #75
Fixed combination keys not working #85
1 parent 8b71574 commit eceb33c

File tree

4 files changed

+34
-25
lines changed

4 files changed

+34
-25
lines changed

src/hotkeys/hotkeys_manager.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __win32_event_filter(self, msg, data):
4646

4747
def __on_press(self, key):
4848
userSettings = self.settings.get_config()
49-
if self.changeKey == True:
49+
if self.changeKey:
5050
keyPressed = getKeyPressed(self.keyboard_listener, key)
5151
if keyPressed not in self.hotkeys:
5252
if ">" in keyPressed:
@@ -93,41 +93,53 @@ def __on_press(self, key):
9393
keyPressed = vk_nb[keyPressed]
9494
except:
9595
pass
96+
9697
for keys in userSettings["Hotkeys"]:
97-
if userSettings["Hotkeys"][keys] == []:
98+
if not userSettings["Hotkeys"][keys]:
9899
userSettings["Hotkeys"][keys] = ""
100+
99101
if keyPressed not in self.hotkey_detection:
100102
self.hotkey_detection.append(keyPressed)
103+
101104
by_hotkey = True
105+
102106
if (
103-
self.hotkey_detection == userSettings["Hotkeys"]["Record_Start"]
104-
and self.macro.record == False
105-
and self.macro.playback == False
107+
self.__is_hotkey_triggered(userSettings["Hotkeys"]["Record_Start"], self.hotkey_detection)
108+
and self.macro.record == False
109+
and self.macro.playback == False
106110
):
107111
self.macro.start_record(by_hotkey)
108112

109113
elif (
110-
self.hotkey_detection == userSettings["Hotkeys"]["Record_Stop"]
111-
and self.macro.record == True
112-
and self.macro.playback == False
114+
self.__is_hotkey_triggered(userSettings["Hotkeys"]["Record_Stop"], self.hotkey_detection)
115+
and self.macro.record == True
116+
and self.macro.playback == False
113117
):
114118
self.macro.stop_record()
115119

116120
elif (
117-
self.hotkey_detection == userSettings["Hotkeys"]["Playback_Start"]
118-
and self.macro.record == False
119-
and self.macro.playback == False
120-
and self.main_app.macro_recorded == True
121+
self.__is_hotkey_triggered(userSettings["Hotkeys"]["Playback_Start"], self.hotkey_detection)
122+
and self.macro.record == False
123+
and self.macro.playback == False
124+
and self.main_app.macro_recorded == True
121125
):
122126
self.macro.start_playback()
123127

124128
elif (
125-
self.hotkey_detection == userSettings["Hotkeys"]["Playback_Stop"]
126-
and self.macro.record == False
127-
and self.macro.playback == True
129+
self.__is_hotkey_triggered(userSettings["Hotkeys"]["Playback_Stop"], self.hotkey_detection)
130+
and self.macro.record == False
131+
and self.macro.playback == True
128132
):
129133
self.macro.stop_playback(by_hotkey)
130134

131135
def __on_release(self, key):
132136
if len(self.hotkey_detection) != 0:
133137
self.hotkey_detection.pop()
138+
139+
def __is_hotkey_triggered(self, hotkey_config, detected_keys):
140+
has_modifier = any("Key." in key for key in hotkey_config)
141+
if has_modifier:
142+
return set(hotkey_config) == set(detected_keys)
143+
else:
144+
return any(key in detected_keys for key in hotkey_config)
145+

src/utils/user_settings.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ def __init__(self, main_app):
1919
self.path_setting = path.join(path.expanduser("~"), "Library", "Application Support", "PyMacroRecord")
2020

2121
self.user_setting = path.join(self.path_setting, "userSettings.json")
22-
self.cached_settings=None
2322

2423
if not path.isdir(self.path_setting) or not path.isfile(self.user_setting):
2524
self.first_time = True
@@ -91,17 +90,15 @@ def init_settings(self):
9190
}
9291
}
9392

94-
self.cached_settings=userSettings
9593
userSettings_json = dumps(userSettings, indent=4)
9694
with open(self.user_setting, "w") as settingFile:
9795
settingFile.write(userSettings_json)
9896

9997
def get_config(self):
10098
"""Get settings of users"""
101-
if self.cached_settings is None:
102-
with open(self.user_setting, "r") as settingFile:
103-
self.cached_settings = load(settingFile)
104-
return self.cached_settings
99+
with open(self.user_setting, "r") as settingFile:
100+
settingFile_json = load(settingFile)
101+
return settingFile_json
105102

106103
def update_settings(self, updatedValues):
107104
with open(self.user_setting, "w") as settingFile:

src/utils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Version:
55
def __init__(self, userSettings, main_app):
66
self.main_app = main_app
7-
self.version = "1.3.0"
7+
self.version = "1.4.0"
88
self.new_version = ""
99
if userSettings["Others"]["Check_update"]:
1010
self.update = self.checkVersion()

src/windows/main/main_app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ def __init__(self):
7979
with open(sys.argv[1], 'r') as record:
8080
loaded_content = load(record)
8181
self.macro.import_record(loaded_content)
82+
self.playBtn = Button(self.center_frame, image=self.playImg, command=self.macro.start_playback)
8283
self.macro_recorded = True
8384
self.macro_saved = True
84-
85-
self.playBtn = Button(self.center_frame, image=self.playImg,
86-
command=self.macro.start_playback if self.macro_recorded else None)
85+
else:
86+
self.playBtn = Button(self.center_frame, image=self.playImg, state=DISABLED)
8787
self.playBtn.pack(side=LEFT, padx=50)
8888

8989
# Record Button

0 commit comments

Comments
 (0)