I'm currently writing code which deals with hotkey implementation. When using the system_hotkey module I get weird behavior from reading the configuration file with hotkeys and registering them. Specifically, I've narrowed down the problem to the point where hotkeys are being registered from a list. The following code shows the isolated problem:
from system_hotkey import SystemHotkey
def test(num):
print(num)
def listHKReg():
hotkeys = [[["control", "1"], "test1"],[["control", "2"], "test2"]]
for h in hotkeys:
hk = SystemHotkey()
hk.register(h[0], callback = lambda x:test(h[1]))
while(True):
pass
def hardCodeHKReg():
hk = SystemHotkey()
hk.register(["control", "1"], callback = lambda x:test("test1"))
hk.register(["control", "2"], callback = lambda x:test("test2"))
while(True):
pass
When registering hotkeys with hardCodeHKReg() there's no issues with proper hotkey mapping. But when registering hotkeys with listHKReg() all hotkeys from the list exhibit the same behavior as the last registered hotkey's action from the list (i.e. ctrl+1 will print "test2").