()
Import the sdl2 bindings and define constants.
Import the sdl2 bindings and define constants.
Import the sdl2 bindings and define constants .
def _import_sdl2():
    """Import the sdl2 bindings and define constants."""
    global sdl2, _smooth_zoom
    global SCAN_TO_SCAN, ALT_SCAN_TO_EASCII, MOD_TO_SCAN
    global KEY_TO_EASCII, SHIFT_KEY_TO_EASCII, CTRL_KEY_TO_EASCII

    with EnvironmentCache() as _sdl_env:

        # look for SDL2.dll / libSDL2.dylib / libSDL2.so:
        # first in LIB_DIR, then in the standard search path
        # user should remove dll from LIB_DIR they want to use another one
        _sdl_env.set('PYSDL2_DLL_PATH', LIB_DIR)
        try:
            from . import sdl2
        except ImportError:
            _sdl_env.set('PYSDL2_DLL_PATH', '')
            # last try, do not catch ImportError
            from . import sdl2
        _smooth_zoom = _bind_gfx_zoomsurface()


    ###############################################################################
    # keyboard codes

    # these are PC keyboard scancodes
    SCAN_TO_SCAN = {
        # top row
        sdl2.SDL_SCANCODE_ESCAPE: scancode.ESCAPE, sdl2.SDL_SCANCODE_1: scancode.N1,
        sdl2.SDL_SCANCODE_2: scancode.N2, sdl2.SDL_SCANCODE_3: scancode.N3,
        sdl2.SDL_SCANCODE_4: scancode.N4, sdl2.SDL_SCANCODE_5: scancode.N5,
        sdl2.SDL_SCANCODE_6: scancode.N6, sdl2.SDL_SCANCODE_7: scancode.N7,
        sdl2.SDL_SCANCODE_8: scancode.N8, sdl2.SDL_SCANCODE_9: scancode.N9,
        sdl2.SDL_SCANCODE_0: scancode.N0, sdl2.SDL_SCANCODE_MINUS: scancode.MINUS,
        sdl2.SDL_SCANCODE_EQUALS: scancode.EQUALS, sdl2.SDL_SCANCODE_BACKSPACE: scancode.BACKSPACE,
        # row 1
        sdl2.SDL_SCANCODE_TAB: scancode.TAB, sdl2.SDL_SCANCODE_Q: scancode.q,
        sdl2.SDL_SCANCODE_W: scancode.w, sdl2.SDL_SCANCODE_E: scancode.e,
        sdl2.SDL_SCANCODE_R: scancode.r, sdl2.SDL_SCANCODE_T: scancode.t,
        sdl2.SDL_SCANCODE_Y: scancode.y, sdl2.SDL_SCANCODE_U: scancode.u,
        sdl2.SDL_SCANCODE_I: scancode.i, sdl2.SDL_SCANCODE_O: scancode.o,
        sdl2.SDL_SCANCODE_P: scancode.p, sdl2.SDL_SCANCODE_LEFTBRACKET: scancode.LEFTBRACKET,
        sdl2.SDL_SCANCODE_RIGHTBRACKET: scancode.RIGHTBRACKET,
        sdl2.SDL_SCANCODE_RETURN: scancode.RETURN, sdl2.SDL_SCANCODE_KP_ENTER: scancode.RETURN,
        # row 2
        sdl2.SDL_SCANCODE_RCTRL: scancode.CTRL, sdl2.SDL_SCANCODE_LCTRL: scancode.CTRL,
        sdl2.SDL_SCANCODE_A: scancode.a, sdl2.SDL_SCANCODE_S: scancode.s,
        sdl2.SDL_SCANCODE_D: scancode.d, sdl2.SDL_SCANCODE_F: scancode.f,
        sdl2.SDL_SCANCODE_G: scancode.g, sdl2.SDL_SCANCODE_H: scancode.h,
        sdl2.SDL_SCANCODE_J: scancode.j, sdl2.SDL_SCANCODE_K: scancode.k,
        sdl2.SDL_SCANCODE_L: scancode.l, sdl2.SDL_SCANCODE_SEMICOLON: scancode.SEMICOLON,
        sdl2.SDL_SCANCODE_APOSTROPHE: scancode.QUOTE, sdl2.SDL_SCANCODE_GRAVE: scancode.BACKQUOTE,
        # row 3
        sdl2.SDL_SCANCODE_LSHIFT: scancode.LSHIFT, sdl2.SDL_SCANCODE_BACKSLASH: scancode.BACKSLASH,
        sdl2.SDL_SCANCODE_Z: scancode.z, sdl2.SDL_SCANCODE_X: scancode.x,
        sdl2.SDL_SCANCODE_C: scancode.c, sdl2.SDL_SCANCODE_V: scancode.v,
        sdl2.SDL_SCANCODE_B: scancode.b, sdl2.SDL_SCANCODE_N: scancode.n,
        sdl2.SDL_SCANCODE_M: scancode.m, sdl2.SDL_SCANCODE_COMMA: scancode.COMMA,
        sdl2.SDL_SCANCODE_PERIOD: scancode.PERIOD, sdl2.SDL_SCANCODE_SLASH: scancode.SLASH,
        sdl2.SDL_SCANCODE_RSHIFT: scancode.RSHIFT, sdl2.SDL_SCANCODE_SYSREQ: scancode.SYSREQ,
        sdl2.SDL_SCANCODE_LALT: scancode.ALT,
        # don't catch right-Alt as it may inhibit AltGr on Windows
        # sdl2.SDL_SCANCODE_RALT: scancode.ALT,
        sdl2.SDL_SCANCODE_SPACE: scancode.SPACE, sdl2.SDL_SCANCODE_CAPSLOCK: scancode.CAPSLOCK,
        # function keys
        sdl2.SDL_SCANCODE_F1: scancode.F1, sdl2.SDL_SCANCODE_F2: scancode.F2,
        sdl2.SDL_SCANCODE_F3: scancode.F3, sdl2.SDL_SCANCODE_F4: scancode.F4,
        sdl2.SDL_SCANCODE_F5: scancode.F5, sdl2.SDL_SCANCODE_F6: scancode.F6,
        sdl2.SDL_SCANCODE_F7: scancode.F7, sdl2.SDL_SCANCODE_F8: scancode.F8,
        sdl2.SDL_SCANCODE_F9: scancode.F9, sdl2.SDL_SCANCODE_F10: scancode.F10,
        sdl2.SDL_SCANCODE_F11: scancode.F11, sdl2.SDL_SCANCODE_F12: scancode.F12,
        # top of keypad
        sdl2.SDL_SCANCODE_NUMLOCKCLEAR: scancode.NUMLOCK,
        sdl2.SDL_SCANCODE_SCROLLLOCK: scancode.SCROLLOCK, sdl2.SDL_SCANCODE_PAUSE: scancode.BREAK,
        # keypad
        sdl2.SDL_SCANCODE_KP_MULTIPLY: scancode.KPTIMES,
        sdl2.SDL_SCANCODE_PRINTSCREEN: scancode.PRINT,
        sdl2.SDL_SCANCODE_KP_7: scancode.KP7, sdl2.SDL_SCANCODE_HOME: scancode.HOME,
        sdl2.SDL_SCANCODE_KP_8: scancode.KP8, sdl2.SDL_SCANCODE_UP: scancode.UP,
        sdl2.SDL_SCANCODE_KP_9: scancode.KP9, sdl2.SDL_SCANCODE_PAGEUP: scancode.PAGEUP,
        sdl2.SDL_SCANCODE_KP_MINUS: scancode.KPMINUS, sdl2.SDL_SCANCODE_KP_4: scancode.KP4,
        sdl2.SDL_SCANCODE_LEFT: scancode.LEFT, sdl2.SDL_SCANCODE_KP_5: scancode.KP5,
        sdl2.SDL_SCANCODE_KP_6: scancode.KP6, sdl2.SDL_SCANCODE_RIGHT: scancode.RIGHT,
        sdl2.SDL_SCANCODE_KP_PLUS: scancode.KPPLUS, sdl2.SDL_SCANCODE_KP_1: scancode.KP1,
        sdl2.SDL_SCANCODE_END: scancode.END, sdl2.SDL_SCANCODE_KP_2: scancode.KP2,
        sdl2.SDL_SCANCODE_DOWN: scancode.DOWN, sdl2.SDL_SCANCODE_KP_3: scancode.KP3,
        sdl2.SDL_SCANCODE_PAGEDOWN: scancode.PAGEDOWN,
        sdl2.SDL_SCANCODE_KP_0: scancode.KP0, sdl2.SDL_SCANCODE_INSERT: scancode.INSERT,
        sdl2.SDL_SCANCODE_KP_PERIOD: scancode.KPPOINT, sdl2.SDL_SCANCODE_DELETE: scancode.DELETE,
        # extensions
        sdl2.SDL_SCANCODE_NONUSBACKSLASH: scancode.INT1,
        # windows keys
        sdl2.SDL_SCANCODE_LGUI: scancode.LSUPER, sdl2.SDL_SCANCODE_RGUI: scancode.RSUPER,
        sdl2.SDL_SCANCODE_MENU: scancode.MENU,
        # Japanese keyboards
        # mapping to SDL scancodes unknown
        #HIRAGANA_KATAKANA = 0x70
        # backslash/underscore on Japanese keyboard
        #INT3 = 0x73
        #HENKAN = 0x79
        # this is a guess based on https://wiki.libsdl.org/SDL_Scancode
        # and http://www.quadibloc.com/comp/scan.htm
        sdl2.SDL_SCANCODE_LANG4: scancode.MUHENKAN,
        sdl2.SDL_SCANCODE_LANG5: scancode.ZENKAKU_HANKAKU,
        sdl2.SDL_SCANCODE_INTERNATIONAL3: scancode.INT4,
        # Korean keyboards
        sdl2.SDL_SCANCODE_LANG2: scancode.HANJA,
        sdl2.SDL_SCANCODE_LANG1: scancode.HAN_YEONG,
    }

    KEY_TO_EASCII = {
        sdl2.SDLK_F1: uea.F1, sdl2.SDLK_F2: uea.F2, sdl2.SDLK_F3: uea.F3, sdl2.SDLK_F4: uea.F4,
        sdl2.SDLK_F5: uea.F5, sdl2.SDLK_F6: uea.F6, sdl2.SDLK_F7: uea.F7, sdl2.SDLK_F8: uea.F8,
        sdl2.SDLK_F9: uea.F9, sdl2.SDLK_F10: uea.F10, sdl2.SDLK_F11: uea.F11,
        sdl2.SDLK_F12: uea.F12, sdl2.SDLK_HOME: uea.HOME, sdl2.SDLK_UP: uea.UP,
        sdl2.SDLK_PAGEUP: uea.PAGEUP, sdl2.SDLK_LEFT: uea.LEFT, sdl2.SDLK_RIGHT: uea.RIGHT,
        sdl2.SDLK_END: uea.END, sdl2.SDLK_DOWN: uea.DOWN, sdl2.SDLK_PAGEDOWN: uea.PAGEDOWN,
        sdl2.SDLK_ESCAPE: uea.ESCAPE, sdl2.SDLK_BACKSPACE: uea.BACKSPACE, sdl2.SDLK_TAB: uea.TAB,
        sdl2.SDLK_RETURN: uea.RETURN, sdl2.SDLK_KP_ENTER: uea.RETURN, sdl2.SDLK_SPACE: uea.SPACE,
        sdl2.SDLK_INSERT: uea.INSERT, sdl2.SDLK_DELETE: uea.DELETE,
    }

    SHIFT_KEY_TO_EASCII = {
        sdl2.SDLK_F1: uea.SHIFT_F1, sdl2.SDLK_F2: uea.SHIFT_F2, sdl2.SDLK_F3: uea.SHIFT_F3,
        sdl2.SDLK_F4: uea.SHIFT_F4, sdl2.SDLK_F5: uea.SHIFT_F5, sdl2.SDLK_F6: uea.SHIFT_F6,
        sdl2.SDLK_F7: uea.SHIFT_F7, sdl2.SDLK_F8: uea.SHIFT_F8, sdl2.SDLK_F9: uea.SHIFT_F9,
        sdl2.SDLK_F10: uea.SHIFT_F10, sdl2.SDLK_F11: uea.SHIFT_F11, sdl2.SDLK_F12: uea.SHIFT_F12,
        sdl2.SDLK_HOME: uea.SHIFT_HOME, sdl2.SDLK_UP: uea.SHIFT_UP,
        sdl2.SDLK_PAGEUP: uea.SHIFT_PAGEUP, sdl2.SDLK_LEFT: uea.SHIFT_LEFT,
        sdl2.SDLK_RIGHT: uea.SHIFT_RIGHT, sdl2.SDLK_END: uea.SHIFT_END,
        sdl2.SDLK_DOWN: uea.SHIFT_DOWN, sdl2.SDLK_PAGEDOWN: uea.SHIFT_PAGEDOWN,
        sdl2.SDLK_ESCAPE: uea.SHIFT_ESCAPE, sdl2.SDLK_BACKSPACE: uea.SHIFT_BACKSPACE,
        sdl2.SDLK_TAB: uea.SHIFT_TAB, sdl2.SDLK_RETURN: uea.SHIFT_RETURN,
        sdl2.SDLK_KP_ENTER: uea.SHIFT_RETURN, sdl2.SDLK_SPACE: uea.SHIFT_SPACE,
        sdl2.SDLK_INSERT: uea.SHIFT_INSERT, sdl2.SDLK_DELETE: uea.SHIFT_DELETE,
        sdl2.SDLK_KP_5: uea.SHIFT_KP5,
    }

    CTRL_KEY_TO_EASCII = {
        sdl2.SDLK_F1: uea.CTRL_F1, sdl2.SDLK_F2: uea.CTRL_F2, sdl2.SDLK_F3: uea.CTRL_F3,
        sdl2.SDLK_F4: uea.CTRL_F4, sdl2.SDLK_F5: uea.CTRL_F5, sdl2.SDLK_F6: uea.CTRL_F6,
        sdl2.SDLK_F7: uea.CTRL_F7, sdl2.SDLK_F8: uea.CTRL_F8, sdl2.SDLK_F9: uea.CTRL_F9,
        sdl2.SDLK_F10: uea.CTRL_F10, sdl2.SDLK_F11: uea.CTRL_F11, sdl2.SDLK_F12: uea.CTRL_F12,
        sdl2.SDLK_HOME: uea.CTRL_HOME, sdl2.SDLK_PAGEUP: uea.CTRL_PAGEUP,
        sdl2.SDLK_LEFT: uea.CTRL_LEFT, sdl2.SDLK_RIGHT: uea.CTRL_RIGHT, sdl2.SDLK_END: uea.CTRL_END,
        sdl2.SDLK_PAGEDOWN: uea.CTRL_PAGEDOWN, sdl2.SDLK_ESCAPE: uea.CTRL_ESCAPE,
        sdl2.SDLK_BACKSPACE: uea.CTRL_BACKSPACE, sdl2.SDLK_TAB: uea.CTRL_TAB,
        sdl2.SDLK_RETURN: uea.CTRL_RETURN, sdl2.SDLK_KP_ENTER: uea.CTRL_RETURN,
        sdl2.SDLK_SPACE: uea.CTRL_SPACE, sdl2.SDLK_PRINTSCREEN: uea.CTRL_PRINT,
        sdl2.SDLK_2: uea.CTRL_2, sdl2.SDLK_6: uea.CTRL_6, sdl2.SDLK_MINUS: uea.CTRL_MINUS,
    }

    ALT_SCAN_TO_EASCII = {
        sdl2.SDL_SCANCODE_1: uea.ALT_1, sdl2.SDL_SCANCODE_2: uea.ALT_2,
        sdl2.SDL_SCANCODE_3: uea.ALT_3, sdl2.SDL_SCANCODE_4: uea.ALT_4,
        sdl2.SDL_SCANCODE_5: uea.ALT_5, sdl2.SDL_SCANCODE_6: uea.ALT_6,
        sdl2.SDL_SCANCODE_7: uea.ALT_7, sdl2.SDL_SCANCODE_8: uea.ALT_8,
        sdl2.SDL_SCANCODE_9: uea.ALT_9, sdl2.SDL_SCANCODE_0: uea.ALT_0,
        sdl2.SDL_SCANCODE_MINUS: uea.ALT_MINUS, sdl2.SDL_SCANCODE_EQUALS: uea.ALT_EQUALS,
        sdl2.SDL_SCANCODE_Q: uea.ALT_q, sdl2.SDL_SCANCODE_W: uea.ALT_w,
        sdl2.SDL_SCANCODE_E: uea.ALT_e, sdl2.SDL_SCANCODE_R: uea.ALT_r,
        sdl2.SDL_SCANCODE_T: uea.ALT_t, sdl2.SDL_SCANCODE_Y: uea.ALT_y,
        sdl2.SDL_SCANCODE_U: uea.ALT_u, sdl2.SDL_SCANCODE_I: uea.ALT_i,
        sdl2.SDL_SCANCODE_O: uea.ALT_o, sdl2.SDL_SCANCODE_P: uea.ALT_p,
        sdl2.SDL_SCANCODE_A: uea.ALT_a, sdl2.SDL_SCANCODE_S: uea.ALT_s,
        sdl2.SDL_SCANCODE_D: uea.ALT_d, sdl2.SDL_SCANCODE_F: uea.ALT_f,
        sdl2.SDL_SCANCODE_G: uea.ALT_g, sdl2.SDL_SCANCODE_H: uea.ALT_h,
        sdl2.SDL_SCANCODE_J: uea.ALT_j, sdl2.SDL_SCANCODE_K: uea.ALT_k,
        sdl2.SDL_SCANCODE_L: uea.ALT_l, sdl2.SDL_SCANCODE_Z: uea.ALT_z,
        sdl2.SDL_SCANCODE_X: uea.ALT_x, sdl2.SDL_SCANCODE_C: uea.ALT_c,
        sdl2.SDL_SCANCODE_V: uea.ALT_v, sdl2.SDL_SCANCODE_B: uea.ALT_b,
        sdl2.SDL_SCANCODE_N: uea.ALT_n, sdl2.SDL_SCANCODE_M: uea.ALT_m,
        sdl2.SDL_SCANCODE_F1: uea.ALT_F1, sdl2.SDL_SCANCODE_F2: uea.ALT_F2,
        sdl2.SDL_SCANCODE_F3: uea.ALT_F3, sdl2.SDL_SCANCODE_F4: uea.ALT_F4,
        sdl2.SDL_SCANCODE_F5: uea.ALT_F5, sdl2.SDL_SCANCODE_F6: uea.ALT_F6,
        sdl2.SDL_SCANCODE_F7: uea.ALT_F7, sdl2.SDL_SCANCODE_F8: uea.ALT_F8,
        sdl2.SDL_SCANCODE_F9: uea.ALT_F9, sdl2.SDL_SCANCODE_F10: uea.ALT_F10,
        sdl2.SDL_SCANCODE_F11: uea.ALT_F11, sdl2.SDL_SCANCODE_F12: uea.ALT_F12,
        sdl2.SDL_SCANCODE_BACKSPACE: uea.ALT_BACKSPACE, sdl2.SDL_SCANCODE_TAB: uea.ALT_TAB,
        sdl2.SDL_SCANCODE_RETURN: uea.ALT_RETURN, sdl2.SDL_SCANCODE_KP_ENTER: uea.ALT_RETURN,
        sdl2.SDL_SCANCODE_SPACE: uea.ALT_SPACE, sdl2.SDL_SCANCODE_PRINTSCREEN: uea.ALT_PRINT,
        sdl2.SDL_SCANCODE_KP_5: uea.ALT_KP5,
    }

    MOD_TO_SCAN = {
        sdl2.KMOD_LSHIFT: scancode.LSHIFT, sdl2.KMOD_RSHIFT: scancode.RSHIFT,
        sdl2.KMOD_LCTRL: scancode.CTRL, sdl2.KMOD_RCTRL: scancode.CTRL,
        sdl2.KMOD_LALT: scancode.ALT,
        # don't catch right-Alt as it may inhibit AltGr on Windows
        #sdl2.KMOD_RALT: scancode.ALT,
    }
def _import_sdl2 ( ) : global sdl2 , _smooth_zoom global SCAN_TO_SCAN , ALT_SCAN_TO_EASCII , MOD_TO_SCAN global KEY_TO_EASCII , SHIFT_KEY_TO_EASCII , CTRL_KEY_TO_EASCII with EnvironmentCache ( ) as _sdl_env : # look for SDL2.dll / libSDL2.dylib / libSDL2.so: # first in LIB_DIR, then in the standard search path # user should remove dll from LIB_DIR they want to use another one _sdl_env . set ( 'PYSDL2_DLL_PATH' , LIB_DIR ) try : from . import sdl2 except ImportError : _sdl_env . set ( 'PYSDL2_DLL_PATH' , '' ) # last try, do not catch ImportError from . import sdl2 _smooth_zoom = _bind_gfx_zoomsurface ( ) ############################################################################### # keyboard codes # these are PC keyboard scancodes SCAN_TO_SCAN = { # top row sdl2 . SDL_SCANCODE_ESCAPE : scancode . ESCAPE , sdl2 . SDL_SCANCODE_1 : scancode . N1 , sdl2 . SDL_SCANCODE_2 : scancode . N2 , sdl2 . SDL_SCANCODE_3 : scancode . N3 , sdl2 . SDL_SCANCODE_4 : scancode . N4 , sdl2 . SDL_SCANCODE_5 : scancode . N5 , sdl2 . SDL_SCANCODE_6 : scancode . N6 , sdl2 . SDL_SCANCODE_7 : scancode . N7 , sdl2 . SDL_SCANCODE_8 : scancode . N8 , sdl2 . SDL_SCANCODE_9 : scancode . N9 , sdl2 . SDL_SCANCODE_0 : scancode . N0 , sdl2 . SDL_SCANCODE_MINUS : scancode . MINUS , sdl2 . SDL_SCANCODE_EQUALS : scancode . EQUALS , sdl2 . SDL_SCANCODE_BACKSPACE : scancode . BACKSPACE , # row 1 sdl2 . SDL_SCANCODE_TAB : scancode . TAB , sdl2 . SDL_SCANCODE_Q : scancode . q , sdl2 . SDL_SCANCODE_W : scancode . w , sdl2 . SDL_SCANCODE_E : scancode . e , sdl2 . SDL_SCANCODE_R : scancode . r , sdl2 . SDL_SCANCODE_T : scancode . t , sdl2 . SDL_SCANCODE_Y : scancode . y , sdl2 . SDL_SCANCODE_U : scancode . u , sdl2 . SDL_SCANCODE_I : scancode . i , sdl2 . SDL_SCANCODE_O : scancode . o , sdl2 . SDL_SCANCODE_P : scancode . p , sdl2 . SDL_SCANCODE_LEFTBRACKET : scancode . LEFTBRACKET , sdl2 . SDL_SCANCODE_RIGHTBRACKET : scancode . RIGHTBRACKET , sdl2 . SDL_SCANCODE_RETURN : scancode . RETURN , sdl2 . SDL_SCANCODE_KP_ENTER : scancode . RETURN , # row 2 sdl2 . SDL_SCANCODE_RCTRL : scancode . CTRL , sdl2 . SDL_SCANCODE_LCTRL : scancode . CTRL , sdl2 . SDL_SCANCODE_A : scancode . a , sdl2 . SDL_SCANCODE_S : scancode . s , sdl2 . SDL_SCANCODE_D : scancode . d , sdl2 . SDL_SCANCODE_F : scancode . f , sdl2 . SDL_SCANCODE_G : scancode . g , sdl2 . SDL_SCANCODE_H : scancode . h , sdl2 . SDL_SCANCODE_J : scancode . j , sdl2 . SDL_SCANCODE_K : scancode . k , sdl2 . SDL_SCANCODE_L : scancode . l , sdl2 . SDL_SCANCODE_SEMICOLON : scancode . SEMICOLON , sdl2 . SDL_SCANCODE_APOSTROPHE : scancode . QUOTE , sdl2 . SDL_SCANCODE_GRAVE : scancode . BACKQUOTE , # row 3 sdl2 . SDL_SCANCODE_LSHIFT : scancode . LSHIFT , sdl2 . SDL_SCANCODE_BACKSLASH : scancode . BACKSLASH , sdl2 . SDL_SCANCODE_Z : scancode . z , sdl2 . SDL_SCANCODE_X : scancode . x , sdl2 . SDL_SCANCODE_C : scancode . c , sdl2 . SDL_SCANCODE_V : scancode . v , sdl2 . SDL_SCANCODE_B : scancode . b , sdl2 . SDL_SCANCODE_N : scancode . n , sdl2 . SDL_SCANCODE_M : scancode . m , sdl2 . SDL_SCANCODE_COMMA : scancode . COMMA , sdl2 . SDL_SCANCODE_PERIOD : scancode . PERIOD , sdl2 . SDL_SCANCODE_SLASH : scancode . SLASH , sdl2 . SDL_SCANCODE_RSHIFT : scancode . RSHIFT , sdl2 . SDL_SCANCODE_SYSREQ : scancode . SYSREQ , sdl2 . SDL_SCANCODE_LALT : scancode . ALT , # don't catch right-Alt as it may inhibit AltGr on Windows # sdl2.SDL_SCANCODE_RALT: scancode.ALT, sdl2 . SDL_SCANCODE_SPACE : scancode . SPACE , sdl2 . SDL_SCANCODE_CAPSLOCK : scancode . CAPSLOCK , # function keys sdl2 . SDL_SCANCODE_F1 : scancode . F1 , sdl2 . SDL_SCANCODE_F2 : scancode . F2 , sdl2 . SDL_SCANCODE_F3 : scancode . F3 , sdl2 . SDL_SCANCODE_F4 : scancode . F4 , sdl2 . SDL_SCANCODE_F5 : scancode . F5 , sdl2 . SDL_SCANCODE_F6 : scancode . F6 , sdl2 . SDL_SCANCODE_F7 : scancode . F7 , sdl2 . SDL_SCANCODE_F8 : scancode . F8 , sdl2 . SDL_SCANCODE_F9 : scancode . F9 , sdl2 . SDL_SCANCODE_F10 : scancode . F10 , sdl2 . SDL_SCANCODE_F11 : scancode . F11 , sdl2 . SDL_SCANCODE_F12 : scancode . F12 , # top of keypad sdl2 . SDL_SCANCODE_NUMLOCKCLEAR : scancode . NUMLOCK , sdl2 . SDL_SCANCODE_SCROLLLOCK : scancode . SCROLLOCK , sdl2 . SDL_SCANCODE_PAUSE : scancode . BREAK , # keypad sdl2 . SDL_SCANCODE_KP_MULTIPLY : scancode . KPTIMES , sdl2 . SDL_SCANCODE_PRINTSCREEN : scancode . PRINT , sdl2 . SDL_SCANCODE_KP_7 : scancode . KP7 , sdl2 . SDL_SCANCODE_HOME : scancode . HOME , sdl2 . SDL_SCANCODE_KP_8 : scancode . KP8 , sdl2 . SDL_SCANCODE_UP : scancode . UP , sdl2 . SDL_SCANCODE_KP_9 : scancode . KP9 , sdl2 . SDL_SCANCODE_PAGEUP : scancode . PAGEUP , sdl2 . SDL_SCANCODE_KP_MINUS : scancode . KPMINUS , sdl2 . SDL_SCANCODE_KP_4 : scancode . KP4 , sdl2 . SDL_SCANCODE_LEFT : scancode . LEFT , sdl2 . SDL_SCANCODE_KP_5 : scancode . KP5 , sdl2 . SDL_SCANCODE_KP_6 : scancode . KP6 , sdl2 . SDL_SCANCODE_RIGHT : scancode . RIGHT , sdl2 . SDL_SCANCODE_KP_PLUS : scancode . KPPLUS , sdl2 . SDL_SCANCODE_KP_1 : scancode . KP1 , sdl2 . SDL_SCANCODE_END : scancode . END , sdl2 . SDL_SCANCODE_KP_2 : scancode . KP2 , sdl2 . SDL_SCANCODE_DOWN : scancode . DOWN , sdl2 . SDL_SCANCODE_KP_3 : scancode . KP3 , sdl2 . SDL_SCANCODE_PAGEDOWN : scancode . PAGEDOWN , sdl2 . SDL_SCANCODE_KP_0 : scancode . KP0 , sdl2 . SDL_SCANCODE_INSERT : scancode . INSERT , sdl2 . SDL_SCANCODE_KP_PERIOD : scancode . KPPOINT , sdl2 . SDL_SCANCODE_DELETE : scancode . DELETE , # extensions sdl2 . SDL_SCANCODE_NONUSBACKSLASH : scancode . INT1 , # windows keys sdl2 . SDL_SCANCODE_LGUI : scancode . LSUPER , sdl2 . SDL_SCANCODE_RGUI : scancode . RSUPER , sdl2 . SDL_SCANCODE_MENU : scancode . MENU , # Japanese keyboards # mapping to SDL scancodes unknown #HIRAGANA_KATAKANA = 0x70 # backslash/underscore on Japanese keyboard #INT3 = 0x73 #HENKAN = 0x79 # this is a guess based on https://wiki.libsdl.org/SDL_Scancode # and http://www.quadibloc.com/comp/scan.htm sdl2 . SDL_SCANCODE_LANG4 : scancode . MUHENKAN , sdl2 . SDL_SCANCODE_LANG5 : scancode . ZENKAKU_HANKAKU , sdl2 . SDL_SCANCODE_INTERNATIONAL3 : scancode . INT4 , # Korean keyboards sdl2 . SDL_SCANCODE_LANG2 : scancode . HANJA , sdl2 . SDL_SCANCODE_LANG1 : scancode . HAN_YEONG , } KEY_TO_EASCII = { sdl2 . SDLK_F1 : uea . F1 , sdl2 . SDLK_F2 : uea . F2 , sdl2 . SDLK_F3 : uea . F3 , sdl2 . SDLK_F4 : uea . F4 , sdl2 . SDLK_F5 : uea . F5 , sdl2 . SDLK_F6 : uea . F6 , sdl2 . SDLK_F7 : uea . F7 , sdl2 . SDLK_F8 : uea . F8 , sdl2 . SDLK_F9 : uea . F9 , sdl2 . SDLK_F10 : uea . F10 , sdl2 . SDLK_F11 : uea . F11 , sdl2 . SDLK_F12 : uea . F12 , sdl2 . SDLK_HOME : uea . HOME , sdl2 . SDLK_UP : uea . UP , sdl2 . SDLK_PAGEUP : uea . PAGEUP , sdl2 . SDLK_LEFT : uea . LEFT , sdl2 . SDLK_RIGHT : uea . RIGHT , sdl2 . SDLK_END : uea . END , sdl2 . SDLK_DOWN : uea . DOWN , sdl2 . SDLK_PAGEDOWN : uea . PAGEDOWN , sdl2 . SDLK_ESCAPE : uea . ESCAPE , sdl2 . SDLK_BACKSPACE : uea . BACKSPACE , sdl2 . SDLK_TAB : uea . TAB , sdl2 . SDLK_RETURN : uea . RETURN , sdl2 . SDLK_KP_ENTER : uea . RETURN , sdl2 . SDLK_SPACE : uea . SPACE , sdl2 . SDLK_INSERT : uea . INSERT , sdl2 . SDLK_DELETE : uea . DELETE , } SHIFT_KEY_TO_EASCII = { sdl2 . SDLK_F1 : uea . SHIFT_F1 , sdl2 . SDLK_F2 : uea . SHIFT_F2 , sdl2 . SDLK_F3 : uea . SHIFT_F3 , sdl2 . SDLK_F4 : uea . SHIFT_F4 , sdl2 . SDLK_F5 : uea . SHIFT_F5 , sdl2 . SDLK_F6 : uea . SHIFT_F6 , sdl2 . SDLK_F7 : uea . SHIFT_F7 , sdl2 . SDLK_F8 : uea . SHIFT_F8 , sdl2 . SDLK_F9 : uea . SHIFT_F9 , sdl2 . SDLK_F10 : uea . SHIFT_F10 , sdl2 . SDLK_F11 : uea . SHIFT_F11 , sdl2 . SDLK_F12 : uea . SHIFT_F12 , sdl2 . SDLK_HOME : uea . SHIFT_HOME , sdl2 . SDLK_UP : uea . SHIFT_UP , sdl2 . SDLK_PAGEUP : uea . SHIFT_PAGEUP , sdl2 . SDLK_LEFT : uea . SHIFT_LEFT , sdl2 . SDLK_RIGHT : uea . SHIFT_RIGHT , sdl2 . SDLK_END : uea . SHIFT_END , sdl2 . SDLK_DOWN : uea . SHIFT_DOWN , sdl2 . SDLK_PAGEDOWN : uea . SHIFT_PAGEDOWN , sdl2 . SDLK_ESCAPE : uea . SHIFT_ESCAPE , sdl2 . SDLK_BACKSPACE : uea . SHIFT_BACKSPACE , sdl2 . SDLK_TAB : uea . SHIFT_TAB , sdl2 . SDLK_RETURN : uea . SHIFT_RETURN , sdl2 . SDLK_KP_ENTER : uea . SHIFT_RETURN , sdl2 . SDLK_SPACE : uea . SHIFT_SPACE , sdl2 . SDLK_INSERT : uea . SHIFT_INSERT , sdl2 . SDLK_DELETE : uea . SHIFT_DELETE , sdl2 . SDLK_KP_5 : uea . SHIFT_KP5 , } CTRL_KEY_TO_EASCII = { sdl2 . SDLK_F1 : uea . CTRL_F1 , sdl2 . SDLK_F2 : uea . CTRL_F2 , sdl2 . SDLK_F3 : uea . CTRL_F3 , sdl2 . SDLK_F4 : uea . CTRL_F4 , sdl2 . SDLK_F5 : uea . CTRL_F5 , sdl2 . SDLK_F6 : uea . CTRL_F6 , sdl2 . SDLK_F7 : uea . CTRL_F7 , sdl2 . SDLK_F8 : uea . CTRL_F8 , sdl2 . SDLK_F9 : uea . CTRL_F9 , sdl2 . SDLK_F10 : uea . CTRL_F10 , sdl2 . SDLK_F11 : uea . CTRL_F11 , sdl2 . SDLK_F12 : uea . CTRL_F12 , sdl2 . SDLK_HOME : uea . CTRL_HOME , sdl2 . SDLK_PAGEUP : uea . CTRL_PAGEUP , sdl2 . SDLK_LEFT : uea . CTRL_LEFT , sdl2 . SDLK_RIGHT : uea . CTRL_RIGHT , sdl2 . SDLK_END : uea . CTRL_END , sdl2 . SDLK_PAGEDOWN : uea . CTRL_PAGEDOWN , sdl2 . SDLK_ESCAPE : uea . CTRL_ESCAPE , sdl2 . SDLK_BACKSPACE : uea . CTRL_BACKSPACE , sdl2 . SDLK_TAB : uea . CTRL_TAB , sdl2 . SDLK_RETURN : uea . CTRL_RETURN , sdl2 . SDLK_KP_ENTER : uea . CTRL_RETURN , sdl2 . SDLK_SPACE : uea . CTRL_SPACE , sdl2 . SDLK_PRINTSCREEN : uea . CTRL_PRINT , sdl2 . SDLK_2 : uea . CTRL_2 , sdl2 . SDLK_6 : uea . CTRL_6 , sdl2 . SDLK_MINUS : uea . CTRL_MINUS , } ALT_SCAN_TO_EASCII = { sdl2 . SDL_SCANCODE_1 : uea . ALT_1 , sdl2 . SDL_SCANCODE_2 : uea . ALT_2 , sdl2 . SDL_SCANCODE_3 : uea . ALT_3 , sdl2 . SDL_SCANCODE_4 : uea . ALT_4 , sdl2 . SDL_SCANCODE_5 : uea . ALT_5 , sdl2 . SDL_SCANCODE_6 : uea . ALT_6 , sdl2 . SDL_SCANCODE_7 : uea . ALT_7 , sdl2 . SDL_SCANCODE_8 : uea . ALT_8 , sdl2 . SDL_SCANCODE_9 : uea . ALT_9 , sdl2 . SDL_SCANCODE_0 : uea . ALT_0 , sdl2 . SDL_SCANCODE_MINUS : uea . ALT_MINUS , sdl2 . SDL_SCANCODE_EQUALS : uea . ALT_EQUALS , sdl2 . SDL_SCANCODE_Q : uea . ALT_q , sdl2 . SDL_SCANCODE_W : uea . ALT_w , sdl2 . SDL_SCANCODE_E : uea . ALT_e , sdl2 . SDL_SCANCODE_R : uea . ALT_r , sdl2 . SDL_SCANCODE_T : uea . ALT_t , sdl2 . SDL_SCANCODE_Y : uea . ALT_y , sdl2 . SDL_SCANCODE_U : uea . ALT_u , sdl2 . SDL_SCANCODE_I : uea . ALT_i , sdl2 . SDL_SCANCODE_O : uea . ALT_o , sdl2 . SDL_SCANCODE_P : uea . ALT_p , sdl2 . SDL_SCANCODE_A : uea . ALT_a , sdl2 . SDL_SCANCODE_S : uea . ALT_s , sdl2 . SDL_SCANCODE_D : uea . ALT_d , sdl2 . SDL_SCANCODE_F : uea . ALT_f , sdl2 . SDL_SCANCODE_G : uea . ALT_g , sdl2 . SDL_SCANCODE_H : uea . ALT_h , sdl2 . SDL_SCANCODE_J : uea . ALT_j , sdl2 . SDL_SCANCODE_K : uea . ALT_k , sdl2 . SDL_SCANCODE_L : uea . ALT_l , sdl2 . SDL_SCANCODE_Z : uea . ALT_z , sdl2 . SDL_SCANCODE_X : uea . ALT_x , sdl2 . SDL_SCANCODE_C : uea . ALT_c , sdl2 . SDL_SCANCODE_V : uea . ALT_v , sdl2 . SDL_SCANCODE_B : uea . ALT_b , sdl2 . SDL_SCANCODE_N : uea . ALT_n , sdl2 . SDL_SCANCODE_M : uea . ALT_m , sdl2 . SDL_SCANCODE_F1 : uea . ALT_F1 , sdl2 . SDL_SCANCODE_F2 : uea . ALT_F2 , sdl2 . SDL_SCANCODE_F3 : uea . ALT_F3 , sdl2 . SDL_SCANCODE_F4 : uea . ALT_F4 , sdl2 . SDL_SCANCODE_F5 : uea . ALT_F5 , sdl2 . SDL_SCANCODE_F6 : uea . ALT_F6 , sdl2 . SDL_SCANCODE_F7 : uea . ALT_F7 , sdl2 . SDL_SCANCODE_F8 : uea . ALT_F8 , sdl2 . SDL_SCANCODE_F9 : uea . ALT_F9 , sdl2 . SDL_SCANCODE_F10 : uea . ALT_F10 , sdl2 . SDL_SCANCODE_F11 : uea . ALT_F11 , sdl2 . SDL_SCANCODE_F12 : uea . ALT_F12 , sdl2 . SDL_SCANCODE_BACKSPACE : uea . ALT_BACKSPACE , sdl2 . SDL_SCANCODE_TAB : uea . ALT_TAB , sdl2 . SDL_SCANCODE_RETURN : uea . ALT_RETURN , sdl2 . SDL_SCANCODE_KP_ENTER : uea . ALT_RETURN , sdl2 . SDL_SCANCODE_SPACE : uea . ALT_SPACE , sdl2 . SDL_SCANCODE_PRINTSCREEN : uea . ALT_PRINT , sdl2 . SDL_SCANCODE_KP_5 : uea . ALT_KP5 , } MOD_TO_SCAN = { sdl2 . KMOD_LSHIFT : scancode . LSHIFT , sdl2 . KMOD_RSHIFT : scancode . RSHIFT , sdl2 . KMOD_LCTRL : scancode . CTRL , sdl2 . KMOD_RCTRL : scancode . CTRL , sdl2 . KMOD_LALT : scancode . ALT , # don't catch right-Alt as it may inhibit AltGr on Windows #sdl2.KMOD_RALT: scancode.ALT, }