# $Id: events.py.in,v 1.9 2003/10/06 02:08:01 mackstann Exp $

import types
import kahakai

kahakaiInst = kahakai.Kahakai.Instance()
screen = kahakaiInst.script_current_screen

if isinstance(kahakaiInst, str):
    print "Error!  What should be a kahakai instance is in fact a string,"
    print "which is weird. You most likely have an error in your userconfig."

_modifiers = dict([(comp.first, comp.second)
                   for comp in kahakai.getXModifiers(screen.display)])

# Define some alias, will use this so the keynames are case insensitive
# (which is not the case for X keyname, like Return != return)

alias = {
# you can add some aliases here
# do not remove the following line !!!
# GENERATED ALIAS TABLE GOES HERE
'cyrillic_ghe_bar' : 'Cyrillic_GHE_bar',
'terminate_server' : 'Terminate_Server',
'hangul_jeonja' : 'Hangul_Jeonja',
'lirasign' : 'LiraSign',
'hangul_rieulsios' : 'Hangul_RieulSios',
'armenian_vo' : 'Armenian_VO',
'pointer_dblclick3' : 'Pointer_DblClick3',
'hangul_j_pieub' : 'Hangul_J_Pieub',
'page_down' : 'Page_Down',
'greek_iotaaccent' : 'Greek_IOTAaccent',
'hangul_cieuc' : 'Hangul_Cieuc',
'hangul_ieung' : 'Hangul_Ieung',
'cyrillic_ka_descender' : 'Cyrillic_KA_descender',
'kana_hi' : 'kana_HI',
'zen_koho' : 'Zen_Koho',
'kana_ho' : 'kana_HO',
'greek_iota' : 'Greek_IOTA',
'overlay1_enable' : 'Overlay1_Enable',
'armenian_lyun' : 'Armenian_LYUN',
'iso_center_object' : 'ISO_Center_Object',
'pesetasign' : 'PesetaSign',
'mousekeys_accel_enable' : 'MouseKeys_Accel_Enable',
'cyrillic_tse' : 'Cyrillic_TSE',
'armenian_gim' : 'Armenian_GIM',
'iso_last_group_lock' : 'ISO_Last_Group_Lock',
'hangul_rieulkiyeog' : 'Hangul_RieulKiyeog',
'serbian_je' : 'Serbian_JE',
'iso_prev_group' : 'ISO_Prev_Group',
'armenian_e' : 'Armenian_E',
'armenian_o' : 'Armenian_O',
'cyrillic_ha_descender' : 'Cyrillic_HA_descender',
'pointer_dblclick_dflt' : 'Pointer_DblClick_Dflt',
'greek_omega' : 'Greek_OMEGA',
'hangul_j_sios' : 'Hangul_J_Sios',
'pointer_right' : 'Pointer_Right',
'pointer_button_dflt' : 'Pointer_Button_Dflt',
'kp_f1' : 'KP_F1',
'kp_f2' : 'KP_F2',
'kp_f3' : 'KP_F3',
'kp_f4' : 'KP_F4',
'cyrillic_u_straight' : 'Cyrillic_U_straight',
'kana_lock' : 'Kana_Lock',
'greek_epsilonaccent' : 'Greek_EPSILONaccent',
'hangul_yae' : 'Hangul_YAE',
'iso_release_both_margins' : 'ISO_Release_Both_Margins',
'ae' : 'AE',
'byelorussian_shortu' : 'Byelorussian_SHORTU',
'kp_equal' : 'KP_Equal',
'eurosign' : 'EuroSign',
'hangul_yeo' : 'Hangul_YEO',
'iso_first_group_lock' : 'ISO_First_Group_Lock',
'armenian_ken' : 'Armenian_KEN',
'hyper_l' : 'Hyper_L',
'super_l' : 'Super_L',
'super_r' : 'Super_R',
'armenian_fe' : 'Armenian_FE',
'hangul_j_nieunjieuj' : 'Hangul_J_NieunJieuj',
'kana_shi' : 'kana_SHI',
'armenian_khe' : 'Armenian_KHE',
'hangul_j_nieun' : 'Hangul_J_Nieun',
'kp_up' : 'KP_Up',
'armenian_vev' : 'Armenian_VEV',
'hangul_posthanja' : 'Hangul_PostHanja',
'hangul_pansios' : 'Hangul_PanSios',
'cyrillic_schwa' : 'Cyrillic_SCHWA',
'hangul_hieuh' : 'Hangul_Hieuh',
'hangul_banja' : 'Hangul_Banja',
'oe' : 'OE',
'hangul_rieulpieub' : 'Hangul_RieulPieub',
'hangul_j_rieulmieum' : 'Hangul_J_RieulMieum',
'hangul_start' : 'Hangul_Start',
'cyrillic_be' : 'Cyrillic_BE',
'pointer_down' : 'Pointer_Down',
'greek_lambda' : 'Greek_LAMBDA',
'iso_next_group_lock' : 'ISO_Next_Group_Lock',
'hangul_we' : 'Hangul_WE',
'kana_shift' : 'Kana_Shift',
'iso_level3_shift' : 'ISO_Level3_Shift',
'kp_next' : 'KP_Next',
'iso_next_group' : 'ISO_Next_Group',
'hangul_j_rieulphieuf' : 'Hangul_J_RieulPhieuf',
'ukranian_i' : 'Ukranian_I',
'iso_enter' : 'ISO_Enter',
'iso_level3_latch' : 'ISO_Level3_Latch',
'pointer_button1' : 'Pointer_Button1',
'pointer_button2' : 'Pointer_Button2',
'pointer_button3' : 'Pointer_Button3',
'pointer_button4' : 'Pointer_Button4',
'pointer_button5' : 'Pointer_Button5',
'hangul_j_mieum' : 'Hangul_J_Mieum',
'hangul_singlecandidate' : 'Hangul_SingleCandidate',
'thorn' : 'THORN',
'iso_group_lock' : 'ISO_Group_Lock',
'greek_omicronaccent' : 'Greek_OMICRONaccent',
'hangul_pieubsios' : 'Hangul_PieubSios',
'scroll_lock' : 'Scroll_Lock',
'pointer_left' : 'Pointer_Left',
'greek_omegaaccent' : 'Greek_OMEGAaccent',
'hangul_j_kiyeogsios' : 'Hangul_J_KiyeogSios',
'nairasign' : 'NairaSign',
'iso_partial_line_down' : 'ISO_Partial_Line_Down',
'armenian_zhe' : 'Armenian_ZHE',
'kp_space' : 'KP_Space',
'cyrillic_shorti' : 'Cyrillic_SHORTI',
'hangul_dikeud' : 'Hangul_Dikeud',
'pointer_drag_dflt' : 'Pointer_Drag_Dflt',
'hangul_tieut' : 'Hangul_Tieut',
'greek_phi' : 'Greek_PHI',
'num_lock' : 'Num_Lock',
'serbian_tshe' : 'Serbian_TSHE',
'shift_l' : 'Shift_L',
'greek_alphaaccent' : 'Greek_ALPHAaccent',
'shift_r' : 'Shift_R',
'hangul_ssangpieub' : 'Hangul_SsangPieub',
'kp_separator' : 'KP_Separator',
'iso_set_margin_right' : 'ISO_Set_Margin_Right',
'armenian_dza' : 'Armenian_DZA',
'hangul_khieuq' : 'Hangul_Khieuq',
'multiplecandidate' : 'MultipleCandidate',
'hangul_j_ssangsios' : 'Hangul_J_SsangSios',
'greek_eta' : 'Greek_ETA',
'first_virtual_screen' : 'First_Virtual_Screen',
'greek_psi' : 'Greek_PSI',
'ukranian_je' : 'Ukranian_JE',
'greek_gamma' : 'Greek_GAMMA',
'greek_upsilonaccent' : 'Greek_UPSILONaccent',
'armenian_sha' : 'Armenian_SHA',
'ukrainian_i' : 'Ukrainian_I',
'cyrillic_che' : 'Cyrillic_CHE',
'serbian_nje' : 'Serbian_NJE',
'pointer_drag1' : 'Pointer_Drag1',
'pointer_drag2' : 'Pointer_Drag2',
'pointer_drag3' : 'Pointer_Drag3',
'pointer_drag4' : 'Pointer_Drag4',
'pointer_drag5' : 'Pointer_Drag5',
'cyrillic_u_macron' : 'Cyrillic_U_macron',
'greek_tau' : 'Greek_TAU',
'hangul_j_phieuf' : 'Hangul_J_Phieuf',
'greek_zeta' : 'Greek_ZETA',
'kana_fu' : 'kana_FU',
'kp_delete' : 'KP_Delete',
'cyrillic_shha' : 'Cyrillic_SHHA',
'kp_down' : 'KP_Down',
'kana_ha' : 'kana_HA',
'kana_he' : 'kana_HE',
'cyrillic_nje' : 'Cyrillic_NJE',
'kana_hu' : 'kana_HU',
'next_virtual_screen' : 'Next_Virtual_Screen',
'cyrillic_ka_vertstroke' : 'Cyrillic_KA_vertstroke',
'previouscandidate' : 'PreviousCandidate',
'kana_ka' : 'kana_KA',
'kana_ke' : 'kana_KE',
'kana_ki' : 'kana_KI',
'kana_ko' : 'kana_KO',
'kana_ku' : 'kana_KU',
'hangul_sios' : 'Hangul_Sios',
'stickykeys_enable' : 'StickyKeys_Enable',
'pointer_upright' : 'Pointer_UpRight',
'hangul_special' : 'Hangul_Special',
'kana_ma' : 'kana_MA',
'kana_me' : 'kana_ME',
'kana_mi' : 'kana_MI',
'hangul_rieulmieum' : 'Hangul_RieulMieum',
'kana_mo' : 'kana_MO',
'kana_mu' : 'kana_MU',
'kana_na' : 'kana_NA',
'kana_ne' : 'kana_NE',
'kana_no' : 'kana_NO',
'kana_nu' : 'kana_NU',
'cyrillic_u_straight_bar' : 'Cyrillic_U_straight_bar',
'greek_chi' : 'Greek_CHI',
'kana_ra' : 'kana_RA',
'kana_re' : 'kana_RE',
'prev_virtual_screen' : 'Prev_Virtual_Screen',
'kana_ri' : 'kana_RI',
'kana_ro' : 'kana_RO',
'kana_ru' : 'kana_RU',
'kana_sa' : 'kana_SA',
'kana_se' : 'kana_SE',
'kana_so' : 'kana_SO',
'kana_su' : 'kana_SU',
'kp_left' : 'KP_Left',
'hangul_ssangkiyeog' : 'Hangul_SsangKiyeog',
'millsign' : 'MillSign',
'sys_req' : 'Sys_Req',
'kana_ta' : 'kana_TA',
'kana_te' : 'kana_TE',
'kana_ti' : 'kana_TI',
'kana_to' : 'kana_TO',
'kana_tu' : 'kana_TU',
'iso_last_group' : 'ISO_Last_Group',
'hangul_rieul' : 'Hangul_Rieul',
'kana_wa' : 'kana_WA',
'kp_prior' : 'KP_Prior',
'kana_wo' : 'kana_WO',
'pointer_dfltbtnnext' : 'Pointer_DfltBtnNext',
'bouncekeys_enable' : 'BounceKeys_Enable',
'hangul_j_ieung' : 'Hangul_J_Ieung',
'hangul_j_jieuj' : 'Hangul_J_Jieuj',
'kana_ya' : 'kana_YA',
'kana_yo' : 'kana_YO',
'kana_yu' : 'kana_YU',
'voidsymbol' : 'VoidSymbol',
'cyrillic_ghe' : 'Cyrillic_GHE',
'rupeesign' : 'RupeeSign',
'cyrillic_i' : 'Cyrillic_I',
'armenian_at' : 'Armenian_AT',
'ukranian_yi' : 'Ukranian_YI',
'shift_lock' : 'Shift_Lock',
'kana_ni' : 'kana_NI',
'kana_tsu' : 'kana_TSU',
'armenian_da' : 'Armenian_DA',
'armenian_pyur' : 'Armenian_PYUR',
'hangul_kiyeogsios' : 'Hangul_KiyeogSios',
'cyrillic_a' : 'Cyrillic_A',
'cyrillic_e' : 'Cyrillic_E',
'cyrillic_en_descender' : 'Cyrillic_EN_descender',
'cyrillic_u' : 'Cyrillic_U',
'kp_page_down' : 'KP_Page_Down',
'armenian_ayb' : 'Armenian_AYB',
'iso_move_line_up' : 'ISO_Move_Line_Up',
'slowkeys_enable' : 'SlowKeys_Enable',
'armenian_hi' : 'Armenian_HI',
'armenian_ho' : 'Armenian_HO',
'greek_mu' : 'Greek_MU',
'hangul_j_rieulkiyeog' : 'Hangul_J_RieulKiyeog',
'greek_nu' : 'Greek_NU',
'armenian_je' : 'Armenian_JE',
'hangul_j_kiyeog' : 'Hangul_J_Kiyeog',
'armenian_ke' : 'Armenian_KE',
'hangul_kkogjidalrinieung' : 'Hangul_KkogjiDalrinIeung',
'greek_pi' : 'Greek_PI',
'kp_right' : 'KP_Right',
'pointer_downleft' : 'Pointer_DownLeft',
'hangul_j_pansios' : 'Hangul_J_PanSios',
'greek_delta' : 'Greek_DELTA',
'hangul_sunkyeongeumphieuf' : 'Hangul_SunkyeongeumPhieuf',
'armenian_nu' : 'Armenian_NU',
'greek_alpha' : 'Greek_ALPHA',
'hangul_nieunhieuh' : 'Hangul_NieunHieuh',
'cyrillic_shcha' : 'Cyrillic_SHCHA',
'hangul_prehanja' : 'Hangul_PreHanja',
'greek_beta' : 'Greek_BETA',
'meta_l' : 'Meta_L',
'meta_r' : 'Meta_R',
'greek_upsilon' : 'Greek_UPSILON',
'iso_fast_cursor_down' : 'ISO_Fast_Cursor_Down',
'armenian_ra' : 'Armenian_RA',
'armenian_re' : 'Armenian_RE',
'greek_omicron' : 'Greek_OMICRON',
'cyrillic_hardsign' : 'Cyrillic_HARDSIGN',
'armenian_se' : 'Armenian_SE',
'greek_xi' : 'Greek_XI',
'pointer_enablekeys' : 'Pointer_EnableKeys',
'armenian_to' : 'Armenian_TO',
'hangul_araeae' : 'Hangul_AraeAE',
'hangul_j_ssangkiyeog' : 'Hangul_J_SsangKiyeog',
'pointer_dblclick1' : 'Pointer_DblClick1',
'pointer_dblclick2' : 'Pointer_DblClick2',
'pointer_dblclick4' : 'Pointer_DblClick4',
'pointer_dblclick5' : 'Pointer_DblClick5',
'hangul_j_rieulhieuh' : 'Hangul_J_RieulHieuh',
'armenian_pe' : 'Armenian_PE',
'zenkaku_hankaku' : 'Zenkaku_Hankaku',
'greek_etaaccent' : 'Greek_ETAaccent',
'schwa' : 'SCHWA',
'hangul_jieuj' : 'Hangul_Jieuj',
'armenian_za' : 'Armenian_ZA',
'hangul_wae' : 'Hangul_WAE',
'dongsign' : 'DongSign',
'iso_prev_group_lock' : 'ISO_Prev_Group_Lock',
'mae_koho' : 'Mae_Koho',
'iso_fast_cursor_left' : 'ISO_Fast_Cursor_Left',
'kana_a' : 'kana_A',
'kana_i' : 'kana_I',
'kana_n' : 'kana_N',
'kana_o' : 'kana_O',
'kana_u' : 'kana_U',
'kana_e' : 'kana_E',
'newsheqelsign' : 'NewSheqelSign',
'audiblebell_enable' : 'AudibleBell_Enable',
'iso_group_shift' : 'ISO_Group_Shift',
'hangul_pieub' : 'Hangul_Pieub',
'hangul_weo' : 'Hangul_WEO',
'hangul_j_yeorinhieuh' : 'Hangul_J_YeorinHieuh',
'hangul_a' : 'Hangul_A',
'hangul_j_hieuh' : 'Hangul_J_Hieuh',
'iso_group_latch' : 'ISO_Group_Latch',
'cruzeirosign' : 'CruzeiroSign',
'hangul_ssangdikeud' : 'Hangul_SsangDikeud',
'armenian_ghat' : 'Armenian_GHAT',
'hangul_sunkyeongeumpieub' : 'Hangul_SunkyeongeumPieub',
'hangul_oe' : 'Hangul_OE',
'serbian_dje' : 'Serbian_DJE',
'armenian_vyun' : 'Armenian_VYUN',
'kp_add' : 'KP_Add',
'cyrillic_o_bar' : 'Cyrillic_O_bar',
'iso_continuous_underline' : 'ISO_Continuous_Underline',
'armenian_ini' : 'Armenian_INI',
'hangul_multiplecandidate' : 'Hangul_MultipleCandidate',
'pointer_dfltbtnprev' : 'Pointer_DfltBtnPrev',
'hangul_ssangsios' : 'Hangul_SsangSios',
'cyrillic_i_macron' : 'Cyrillic_I_macron',
'armenian_yech' : 'Armenian_YECH',
'iso_lock' : 'ISO_Lock',
'greek_iotadiaeresis' : 'Greek_IOTAdiaeresis',
'iso_level3_lock' : 'ISO_Level3_Lock',
'iso_emphasize' : 'ISO_Emphasize',
'armenian_tso' : 'Armenian_TSO',
'cyrillic_zhe' : 'Cyrillic_ZHE',
'armenian_tsa' : 'Armenian_TSA',
'pointer_upleft' : 'Pointer_UpLeft',
'hangul_j_rieultieut' : 'Hangul_J_RieulTieut',
'mousekeys_enable' : 'MouseKeys_Enable',
'armenian_ben' : 'Armenian_BEN',
'greek_sigma' : 'Greek_SIGMA',
'alt_l' : 'Alt_L',
'alt_r' : 'Alt_R',
'hangul_j_nieunhieuh' : 'Hangul_J_NieunHieuh',
'kp_divide' : 'KP_Divide',
'serbian_dze' : 'Serbian_DZE',
'hangul_j_rieulsios' : 'Hangul_J_RieulSios',
'greek_epsilon' : 'Greek_EPSILON',
'armenian_men' : 'Armenian_MEN',
'kp_0' : 'KP_0',
'kp_1' : 'KP_1',
'kp_2' : 'KP_2',
'kp_3' : 'KP_3',
'kp_4' : 'KP_4',
'kp_5' : 'KP_5',
'kp_6' : 'KP_6',
'kp_7' : 'KP_7',
'kp_8' : 'KP_8',
'kp_9' : 'KP_9',
'kp_insert' : 'KP_Insert',
'accessx_enable' : 'AccessX_Enable',
'kp_begin' : 'KP_Begin',
'cyrillic_che_descender' : 'Cyrillic_CHE_descender',
'control_l' : 'Control_L',
'control_r' : 'Control_R',
'overlay2_enable' : 'Overlay2_Enable',
'pointer_up' : 'Pointer_Up',
'hangul_previouscandidate' : 'Hangul_PreviousCandidate',
'pointer_downright' : 'Pointer_DownRight',
'hangul_j_tieut' : 'Hangul_J_Tieut',
'eng' : 'ENG',
'iso_fast_cursor_right' : 'ISO_Fast_Cursor_Right',
'hangul_yeorinhieuh' : 'Hangul_YeorinHieuh',
'hangul_nieun' : 'Hangul_Nieun',
'greek_theta' : 'Greek_THETA',
'hangul_araea' : 'Hangul_AraeA',
'hangul_hanja' : 'Hangul_Hanja',
'cyrillic_de' : 'Cyrillic_DE',
'kp_multiply' : 'KP_Multiply',
'kp_subtract' : 'KP_Subtract',
'iso_discontinuous_underline' : 'ISO_Discontinuous_Underline',
'cyrillic_ef' : 'Cyrillic_EF',
'cyrillic_el' : 'Cyrillic_EL',
'cyrillic_em' : 'Cyrillic_EM',
'cyrillic_en' : 'Cyrillic_EN',
'cyrillic_er' : 'Cyrillic_ER',
'cyrillic_es' : 'Cyrillic_ES',
'iso_level2_latch' : 'ISO_Level2_Latch',
'cyrillic_yeru' : 'Cyrillic_YERU',
'iso_release_margin_right' : 'ISO_Release_Margin_Right',
'colonsign' : 'ColonSign',
'cyrillic_sha' : 'Cyrillic_SHA',
'hangul_ssangjieuj' : 'Hangul_SsangJieuj',
'eth' : 'ETH',
'hangul_ae' : 'Hangul_AE',
'cyrillic_ha' : 'Cyrillic_HA',
'cyrillic_ie' : 'Cyrillic_IE',
'cyrillic_io' : 'Cyrillic_IO',
'cyrillic_je' : 'Cyrillic_JE',
'kp_end' : 'KP_End',
'cyrillic_ka' : 'Cyrillic_KA',
'iso_release_margin_left' : 'ISO_Release_Margin_Left',
'macedonia_gje' : 'Macedonia_GJE',
'hangul_romaja' : 'Hangul_Romaja',
'kana_chi' : 'kana_CHI',
'kp_home' : 'KP_Home',
'hangul_rieulhieuh' : 'Hangul_RieulHieuh',
'iso_set_margin_left' : 'ISO_Set_Margin_Left',
'hiragana_katakana' : 'Hiragana_Katakana',
'hyper_r' : 'Hyper_R',
'cyrillic_pe' : 'Cyrillic_PE',
'iso_fast_cursor_up' : 'ISO_Fast_Cursor_Up',
'kp_enter' : 'KP_Enter',
'hangul_phieuf' : 'Hangul_Phieuf',
'cyrillic_te' : 'Cyrillic_TE',
'hangul_mieum' : 'Hangul_Mieum',
'cyrillic_ve' : 'Cyrillic_VE',
'hangul_codeinput' : 'Hangul_Codeinput',
'hangul_nieunjieuj' : 'Hangul_NieunJieuj',
'hangul_rieulyeorinhieuh' : 'Hangul_RieulYeorinHieuh',
'wonsign' : 'WonSign',
'serbian_lje' : 'Serbian_LJE',
'cyrillic_o' : 'Cyrillic_O',
'kp_tab' : 'KP_Tab',
'cyrillic_ya' : 'Cyrillic_YA',
'pointer_accelerate' : 'Pointer_Accelerate',
'cyrillic_yu' : 'Cyrillic_YU',
'iso_first_group' : 'ISO_First_Group',
'cyrillic_ze' : 'Cyrillic_ZE',
'hangul_end' : 'Hangul_End',
'armenian_tche' : 'Armenian_TCHE',
'kp_page_up' : 'KP_Page_Up',
'hangul_sunkyeongeummieum' : 'Hangul_SunkyeongeumMieum',
'greek_iotadieresis' : 'Greek_IOTAdieresis',
'cyrillic_lje' : 'Cyrillic_LJE',
'hangul_wa' : 'Hangul_WA',
'hangul_wi' : 'Hangul_WI',
'hangul_j_kkogjidalrinieung' : 'Hangul_J_KkogjiDalrinIeung',
'hangul_ya' : 'Hangul_YA',
'hangul_ye' : 'Hangul_YE',
'hangul_yi' : 'Hangul_YI',
'hangul_yo' : 'Hangul_YO',
'hangul_yu' : 'Hangul_YU',
'ukrainian_ie' : 'Ukrainian_IE',
'greek_rho' : 'Greek_RHO',
'hangul_j_dikeud' : 'Hangul_J_Dikeud',
'cyrillic_zhe_descender' : 'Cyrillic_ZHE_descender',
'macedonia_kje' : 'Macedonia_KJE',
'hangul_kiyeog' : 'Hangul_Kiyeog',
'hangul_j_rieul' : 'Hangul_J_Rieul',
'ffrancsign' : 'FFrancSign',
'kanji_bangou' : 'Kanji_Bangou',
'caps_lock' : 'Caps_Lock',
'eisu_shift' : 'Eisu_Shift',
'iso_partial_space_left' : 'ISO_Partial_Space_Left',
'hangul_j_khieuq' : 'Hangul_J_Khieuq',
'greek_upsilondieresis' : 'Greek_UPSILONdieresis',
'backspace' : 'BackSpace',
'greek_kappa' : 'Greek_KAPPA',
'hangul_rieultieut' : 'Hangul_RieulTieut',
'hangul_eo' : 'Hangul_EO',
'hangul_eu' : 'Hangul_EU',
'armenian_tyun' : 'Armenian_TYUN',
'cyrillic_softsign' : 'Cyrillic_SOFTSIGN',
'ukrainian_yi' : 'Ukrainian_YI',
'ecusign' : 'EcuSign',
'singlecandidate' : 'SingleCandidate',
'hangul_e' : 'Hangul_E',
'hangul_i' : 'Hangul_I',
'hangul_o' : 'Hangul_O',
'page_up' : 'Page_Up',
'accessx_feedback_enable' : 'AccessX_Feedback_Enable',
'hangul_u' : 'Hangul_U',
'repeatkeys_enable' : 'RepeatKeys_Enable',
'hangul_j_pieubsios' : 'Hangul_J_PieubSios',
'hangul_rieulphieuf' : 'Hangul_RieulPhieuf',
'iso_partial_line_up' : 'ISO_Partial_Line_Up',
'greek_lamda' : 'Greek_LAMDA',
'kp_decimal' : 'KP_Decimal',
'iso_move_line_down' : 'ISO_Move_Line_Down',
'iso_left_tab' : 'ISO_Left_Tab',
'cyrillic_dzhe' : 'Cyrillic_DZHE',
'cyrillic_che_vertstroke' : 'Cyrillic_CHE_vertstroke',
'hangul_j_cieuc' : 'Hangul_J_Cieuc',
'hangul_j_rieulpieub' : 'Hangul_J_RieulPieub',
'armenian_cha' : 'Armenian_CHA',
'henkan_mode' : 'Henkan_Mode',
'korean_won' : 'Korean_Won',
'iso_partial_space_right' : 'ISO_Partial_Space_Right',
'macedonia_dse' : 'Macedonia_DSE',
'last_virtual_screen' : 'Last_Virtual_Screen',
'hangul_jamo' : 'Hangul_Jamo',
'ukrainian_ghe_with_upturn' : 'Ukrainian_GHE_WITH_UPTURN'
# GENERATED ALIAS TABLE GOES HERE
}

for mod in ['MoveResizeMask']:
    _modifiers[mod] = getattr(kahakai, mod)

def warn(s):
    print "*** Warning: %s" % s

class Modifiers(object):
    def __init__(self, mods=0, nmods=0):
        self.mod  = mods
        self.nmod = nmods

    def fromString(s):
        if s in _modifiers:
            return Modifiers(_modifiers[s])
        else:
            warn("Unknown modifier %s" % s)
            return Modifiers()

    def normalize(obj):
        if isinstance(obj, Modifiers):
            return obj
        elif isinstance(obj, str):
            return Modifiers.fromString(obj)
        elif isinstance(obj, int):
            return Modifiers(mods=obj)
        elif isinstance(obj, types.NoneType):
            return Modifiers()
        else:
            warn("Wrong type for a modifier: %s with type %s."%(obj, type(obj)))
            return Modifiers()
        
    def __add__(self, other):
        if isinstance(other, str):
            if other in _modifiers:                
                return self + Modifiers(_modifiers[other])
            else:
                warn("Unknown modifier %s" % other)
        elif isinstance(other, Modifiers):
            return Modifiers(self.mod  | other.mod,
                             self.nmod | other.nmod)
        elif isinstance(other, int):
            return Modifiers(self.mod | other,
                             self.nmod)
        else:
            raise ValueError, "Can't add Modifiers and %s objects" % type(other)

    def __sub__(self, other):
        return self + (-Modifiers.normalize(other))

    def __repr__(self):
        return '<Modifiers: mods = %s, nmods = %s>' % (self.mod, self.nmod)

    def __neg__(self):
        return Modifiers(self.nmod, self.mod)

    fromString = staticmethod(fromString)
    normalize  = staticmethod(normalize)

# Define some common modifiers
Ctrl   = Modifiers.fromString('Control_L')
Alt    = Modifiers.fromString('Alt_L')
Shift  = Modifiers.fromString('Shift_L')
Super  = Modifiers.fromString('Super_L')

MoveResizeMask  = Modifiers.fromString('MoveResizeMask')

if 'Mode_switch' in _modifiers:
    AltGr  = Modifiers.fromString('Mode_switch')
else:
    AltGr  = Modifiers()	

C, A, S, W = Ctrl, Alt, Shift, Super

class ActionEvent(object):
    delayBreaks = []

    def __init__(self, delay=0.0):
        self.delay = delay

    def set(self, action):
        # Decompose delay into second and micro second
        action.delay.tv_sec  = int(self.delay)
        action.delay.tv_usec = (self.delay - int(self.delay)) * 1e6

        action.delay_breaks = kahakai.Vector_int()
        for delayBreak in self.delayBreaks:
            action.delay_breaks.append(delayBreak)

class _Default: pass

class KeyEvent(ActionEvent):

    def __init__(self, a, b=_Default, replay=False, delay=0):
        ActionEvent.__init__(self, delay)
        # we can be called with either ("keyname"), or (modifiers, "keyname"),
        # so at this point we don't know which is which, thus the generic
        # names `a' and `b'

        # and here we determine which is which
        if b is _Default:
            # We are just called with a keyname
            modifiers, keyName = Modifiers(), a
        else:
            # We are called with modifier, keyname
            modifiers, keyName = a, b

        modifiers = Modifiers.normalize(modifiers)

        if not keyName:
            self.keySym = 0
        else:
            self.keySym = self._parseKey(keyName)
            
        self.nmod, self.mod = modifiers.nmod, modifiers.mod
        self.replay = replay

    def _parseKey(self, keyName):
        if isinstance(keyName, (int, long)): # Keycode
            return keyName

        if len(keyName) == 1:
            keyName = keyName.lower()

        keyName = alias.get(keyName.lower(), keyName)
 
        keySym = kahakai.XStringToKeysym(keyName)
		
        if keySym == kahakai.NoSymbol and len(keyName) > 1:
            keySym = kahakai.XStringToKeysym(keyName.capitalize())

            if keySym == kahakai.NoSymbol:
                print "** Warning: %s not a valid key name" % keyName
                return None

        return keySym

        
    def set(self, action):
        if not self.keySym: return False

        ActionEvent.set(self, action)
        
        action.type   = self.type
        action.replay = self.replay
        action.detail = self.keySym
        action.nmod, action.mod = self.nmod, self.mod

        return True

    def bindToCommand(self, screen, command):
        action = kahakai.Action()
        _objects.append(action)
        if not self.set(action): return        
        action.command = command

        for actionList in screen.config.awinacts, screen.config.rootacts:
            actionList.append(action)

class KeyPress(KeyEvent):
    type = kahakai.KeyPress

class KeyRelease(KeyEvent):
    type = kahakai.KeyRelease

class SimpleActionEvent(ActionEvent):
    def __init__(self, modifiers=Modifiers(), delay=0):
        ActionEvent.__init__(self, delay)
            
        modifiers = Modifiers.normalize(modifiers)
        
        self.nmod, self.mod = modifiers.nmod, modifiers.mod

    def set(self, action):
        ActionEvent.set(self, action)
        
        action.type   = self.type
        action.detail = 0
        action.nmod, action.mod = self.nmod, self.mod
        
        return True

class EnterNotify(SimpleActionEvent):
    type = kahakai.EnterNotify
    delayBreaks = kahakai.LeaveNotify,

class LeaveNotify(SimpleActionEvent):
    type = kahakai.LeaveNotify
    delayBreaks = kahakai.EnterNotify,

class MapRequest(SimpleActionEvent):
    type = kahakai.MapRequest

class MouseEvent(ActionEvent):
    def __init__(self, a, b=None, replay=False, delay=0):
        # see KeyEvent for notes about arguments a and b
        ActionEvent.__init__(self, delay);

        if b is None: 
            # We are just called with a buttonName
            modifiers, buttonName = Modifiers(), a
        else:
            # We are called modifier, buttonName
            modifiers, buttonName = a, b

        modifiers = Modifiers.normalize(modifiers)
        
        self.detail = self._parseButton(buttonName)
        self.nmod, self.mod = modifiers.nmod, modifiers.mod
        self.replay = replay

    def set(self, action):
        if not self.detail: return False

        ActionEvent.set(self, action)
        
        action.type   = self.type
        action.detail = self.detail
        action.replay = self.replay
        action.nmod, action.mod = self.nmod, self.mod

        return True
    
    def _parseButton(self, buttonName):
        buttons = {
            'anybutton': 0,
            'button1': kahakai.Button1,
            'button2': kahakai.Button2,
            'button3': kahakai.Button3,
            'button4': kahakai.Button4,
            'button5': kahakai.Button5,
            }

        if buttonName.lower() in buttons:
            return buttons[buttonName.lower()]
        elif buttonName.startswith('button'):
            return int(buttonName[len('button'):])
        else:
            warn("Unknown button: %s" % buttonName)

class ButtonPress(MouseEvent):
    type = kahakai.ButtonPress

class DoubleClick(MouseEvent):
    type = kahakai.DoubleClick

class ButtonRelease(MouseEvent):
    type = kahakai.ButtonRelease
