Skip to content

Commit

Permalink
fix sticky modifier bug
Browse files Browse the repository at this point in the history
  • Loading branch information
111116 committed Feb 6, 2020
1 parent 7ce40b7 commit e224f2a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,16 @@ def convertKeyCode(keyCode):
}
return a.get(keyCode, "[unknown]");

modflag = {
"[left-shift]" : 0b000000100000000000000010,
"[right-shift]" : 0b000000100000000000000100,
"[left-ctrl]" : 0b000001000000000000000001,
"[right-ctrl]" : 0b000001000010000000000000,
"[left-option]" : 0b000010000000000000100000,
"[right-option]" : 0b000010000000000001000000,
"[left-cmd]" : 0b000100000000000000001000,
"[right-cmd]" : 0b000100000000000000010000
};


# create the transparent window
Expand Down Expand Up @@ -175,6 +185,7 @@ def convertKeyCode(keyCode):
label.pack()


# keyboard area status
l = 0
r = 0

Expand All @@ -184,12 +195,18 @@ def CGEventCallback(proxy, type, event, refcon):
if (type != kCGEventKeyDown and type != kCGEventFlagsChanged and type != kCGEventKeyUp):
return event;
keyCode = CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode);
keyname = convertKeyCode(keyCode);
s = ""
if (type == kCGEventKeyDown):
s = "down";
if (type == kCGEventKeyUp):
s = "up";
keyname = convertKeyCode(keyCode);
if type == kCGEventFlagsChanged:
if (CGEventGetFlags(event) & modflag.get(keyname,0)) == modflag.get(keyname,1):
s = "down"
else:
s = "up"

# calculate current keyboard state
global l;
global r;
Expand Down

0 comments on commit e224f2a

Please sign in to comment.