code: def _specialKeyEvent(key, upDown):
      
      assert upDown in ('up', 'down'), "upDown argument must be 'up' or 'down'"
  
      key_code = special_key_translate_table[key]
  
      ev = AppKit.NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
              Quartz.NSSystemDefined, # type
              (0,0), # location
              0xa00 if upDown == 'down' else 0xb00, # flags
              0, # timestamp
              0, # window
              0, # ctx
              8, # subtype
              (key_code << 16) | ((0xa if upDown == 'down' else 0xb) << 8), # data1
              -1 # data2
          )
  
      Quartz.CGEventPost(0, ev.CGEvent())
docs: Helper method for special keys.
  
      Source: http://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac