code: def press(self, key_code):
          
          if key_code >= 128:
              # Media key
              ev = NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
                  14, # type
                  (0, 0), # location
                  0xa00, # flags
                  0, # timestamp
                  0, # window
                  0, # ctx
                  8, # subtype
                  ((key_code-128) << 16) | (0xa << 8), # data1
                  -1 # data2
              )
              Quartz.CGEventPost(0, ev.CGEvent())
          else:
              # Regular key
              # Apply modifiers if necessary
              event_flags = 0
              if self.current_modifiers["shift"]:
                  event_flags += Quartz.kCGEventFlagMaskShift
              if self.current_modifiers["caps"]:
                  event_flags += Quartz.kCGEventFlagMaskAlphaShift
              if self.current_modifiers["alt"]:
                  event_flags += Quartz.kCGEventFlagMaskAlternate
              if self.current_modifiers["ctrl"]:
                  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)
              time.sleep(0.01)
docs: Sends a 'down' event for the specified scan code