Skip to content

Commit

Permalink
Fix key press on macOS: key is not considered held down
Browse files Browse the repository at this point in the history
  • Loading branch information
File5 authored and boppreh committed Aug 29, 2021
1 parent 0ef92be commit 00ec7d9
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions keyboard/_darwinkeyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ def press(self, key_code):
Quartz.CGEventPost(0, ev.CGEvent())
else:
# Regular key
# Update modifiers if necessary
if key_code == 0x37: # cmd
self.current_modifiers["cmd"] = True
elif key_code == 0x38 or key_code == 0x3C: # shift or right shift
self.current_modifiers["shift"] = True
elif key_code == 0x39: # caps lock
self.current_modifiers["caps"] = True
elif key_code == 0x3A: # alt
self.current_modifiers["alt"] = True
elif key_code == 0x3B: # ctrl
self.current_modifiers["ctrl"] = True

# Apply modifiers if necessary
event_flags = 0
if self.current_modifiers["shift"]:
Expand All @@ -267,18 +279,6 @@ def press(self, key_code):
event_flags += Quartz.kCGEventFlagMaskControl
if self.current_modifiers["cmd"]:
event_flags += Quartz.kCGEventFlagMaskCommand

# Update modifiers if necessary
if key_code == 0x37: # cmd
self.current_modifiers["cmd"] = True
elif key_code == 0x38 or key_code == 0x3C: # shift or right shift
self.current_modifiers["shift"] = True
elif key_code == 0x39: # caps lock
self.current_modifiers["caps"] = True
elif key_code == 0x3A: # alt
self.current_modifiers["alt"] = True
elif key_code == 0x3B: # ctrl
self.current_modifiers["ctrl"] = True
event = Quartz.CGEventCreateKeyboardEvent(None, key_code, True)
Quartz.CGEventSetFlags(event, event_flags)
Quartz.CGEventPost(Quartz.kCGHIDEventTap, event)
Expand Down

0 comments on commit 00ec7d9

Please sign in to comment.