Skip to content

Commit

Permalink
hotfix empty/None key
Browse files Browse the repository at this point in the history
  • Loading branch information
wasiejen committed Oct 14, 2024
1 parent ab593c1 commit 3e45d28
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
8 changes: 4 additions & 4 deletions free_snap_tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

# Define File name for saving of everything, can be any filetype
# But .txt or .cfg recommended for easier editing
# CONSTANTS.FILE_NAME = 'FSTconfig.txt'
CONSTANTS.FILE_NAME = 'FSTconfig_test.txt'
# CONSTANTS.FILE_NAME = 'allinone.txt'
CONSTANTS.FILE_NAME = 'FSTconfig.txt'
# CONSTANTS.FILE_NAME = 'FSTconfig_test.txt'


# Control key combinations (vk_code and/or key_string)
# (1,2 or more keys possible - depends on rollover of your keyboard)
Expand Down Expand Up @@ -87,7 +87,7 @@ def __init__(self, root, fst_keyboard):
self.context_menu.add_separator()
self.context_menu.add_command(label="Close Indicator", command=self.close_window)
self.context_menu.add_command(label="Toggle Crosshair", command=self.toggle_crosshair)
#self.context_menu.add_command(label="Display internal state", command=self._fst.display_internal_repr_groups)
self.context_menu.add_command(label="Display internal state", command=self._fst.display_internal_repr_groups)

# Bind right-click to show the context menu
self.canvas.bind("<Button-3>", self.show_context_menu)
Expand Down
28 changes: 16 additions & 12 deletions fst_keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ def convert_to_vk_code(self, key):
except KeyError:
try:
key_int = int(key)
if 0 < key_int < 256:
###XXX 241014-0223
if 0 <= key_int < 256:
# if 0 < key_int < 256:
return key_int
except ValueError as error:
print(error)
Expand Down Expand Up @@ -175,8 +177,9 @@ def extract_data_from_key(key_string):
constraints = [self._arg_manager.ALIAS_MAX_DELAY_IN_MS, self._arg_manager.ALIAS_MIN_DELAY_IN_MS]

# if string empty, stop
if key_string == '':
return False
###XXX 241014-0223 to enable None ke with empty string
# if key_string == '':
# return False

# recognition of mofidiers +, -, !, ^
# only interpret it as such when more then one char is in key
Expand All @@ -201,10 +204,7 @@ def extract_data_from_key(key_string):

# convert string to actual vk_code
vk_code = self.convert_to_vk_code(key_string)
###XXX None Key handling s up to prevent double eval of constraints and is always valid in trigger
if vk_code == 0:
key_modifier == 'up'


if key_modifier is None:
new_element = (Key(vk_code, constraints=constraints, key_string=key_string))
elif key_modifier == 'down':
Expand All @@ -230,7 +230,9 @@ def convert_key_string_group(list_of_strings, is_trigger_group = False):
key_group.append(new_element)
elif isinstance(new_element, Key):
key_press, key_releae = new_element.get_key_events()
key_group.append(key_press)
###XXX hacks to enable empty ke with only one + element
if new_element.vk_code > 0:
key_group.append(key_press)
# if not in trigger group - so Key Instances as triggers are handled correctly
if not is_trigger_group:
key_group.append(key_releae)
Expand Down Expand Up @@ -746,8 +748,8 @@ def is_trigger_activated(current_ke, trigger_group):
# to be not used to filter out opposing sim keys
if alias_fired:
self.state_manager.remove_key_press_state(current_ke.vk_code)
if CONSTANTS.DEBUG4:
print(f"D4: -- removed {current_ke} from pressed keys")
if CONSTANTS.DEBUG3:
print(f"D3: -- removed {current_ke} from pressed keys")
if CONSTANTS.DEBUG4:
print(f"D4: {"-- | XX" if is_simulated else "XX"} SUPPRESSED: {current_ke}")

Expand Down Expand Up @@ -827,6 +829,8 @@ def check_debug_numpad_actions(self):
CONSTANTS.DEBUG3 = not CONSTANTS.DEBUG3
if self.check_for_combination(['num4']):
CONSTANTS.DEBUG4 = not CONSTANTS.DEBUG4
if self.check_for_combination(['num5']):
self.display_internal_repr_groups()
if self.check_for_combination(['num7']):
pprint.pp(f"real_key_state: {self.state_manager._real_key_press_states_dict}")
pprint.pp(f"sim_key_state: {self.state_manager._simulated_key_press_states_dict}")
Expand Down Expand Up @@ -880,9 +884,9 @@ def reset_macro_sequence_by_alias(self, alias_name, current_ke = ''):
try:
macro_to_reset = self._macros_alias_dict[alias_name]
macro_to_reset.reset_sequence_counter()
print(f"--- Macro ({alias_name}) reseted successfully by {current_ke}")
if CONSTANTS.DEBUG4:
print(f"D4: -- Macro ({alias_name}) reseted successfully by {current_ke}")
except KeyError:

print(f"--- No Macro Sequence with name {alias_name} - reset failed")
if CONSTANTS.DEBUG:
print(f"all sequence names: {self._macros_alias_dict.keys()}")
Expand Down
12 changes: 7 additions & 5 deletions fst_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,12 @@ def display_groups(self):
for group in self._macros_hr:
alias, *group = group
group = group[0]
position = len(alias)-2
first_line = f"{alias} " + f'\n{' '*position}:: '.join([', '.join(group[0]),', '.join(group[1])])
position = len(alias)-1
first_line = f"{alias} {', '.join(group[0])} :"
print(first_line)
if len(group) > 2:
for gr in group[2:]:
print(f"{' '*position} : " + ', '.join(gr))
if len(group) > 1:
for gr in group[1:]:
print(f"{' '*position}: " + ', '.join(gr))

def add_group(self, new_group, data_object):
"""
Expand Down Expand Up @@ -1026,6 +1026,8 @@ def extract_delays(arg):
if arg == "-debug":
self.DEBUG = True
CONSTANTS.DEBUG = True
if arg == "-debug_numpad":
CONSTANTS.DEBUG_NUMPAD = True
# start directly without showing the menu
elif arg == "-nomenu":
self.MENU_ENABLED = False
Expand Down
4 changes: 2 additions & 2 deletions fst_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def run(self):
if self.reset:
self.macro_stop_event = Event()
self.reset = False
print(f"{self.alias_name} reset")
#print(f"D4: Repeat: {self.alias_name} reset")
else:
print(f"{self.alias_name} execute")
#print(f"D4: Repeat: {self.alias_name} execute")
self._fst.start_macro_playback(self.alias_name, self._fst.key_group_by_alias[self.alias_name], self.macro_stop_event)
for index in range(self.number_of_increments):
if self.stop_event.is_set():
Expand Down

0 comments on commit 3e45d28

Please sign in to comment.