#NEWLINE# def _specialKeyEvent( key , upDown ) : #NEWLINE# #INDENT# ' Helper method for special keys.\n\n    Source: http://stackoverflow.com/questions/11045814/emulate-media-key-press-on-mac\n    ' #NEWLINE# assert ( upDown in ( 'up' , 'down' ) ) , "upDown argument must be 'up' or 'down'" #NEWLINE# key_code = special_key_translate_table [ key_code ] #NEWLINE# ev = AppKit . NSEvent . otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_ ( Quartz . NSSystemDefined , ( 0 , 0 ) , ( 2560 if ( upDown == 'down' ) else 2816 ) , 0 , 0 , 0 , 8 , ( ( key_code << 16 ) | ( ( 10 if ( upDown == 'down' ) else 11 ) << 8 ) ) , ( - 1 ) ) #NEWLINE# Quartz . CGEventPost ( 0 , ev . CGEvent ( ) )