import sys
import ctypes
from types import SimpleNamespace

from .function import *
from .core import *


def _get_evt_cst(name):
    return ctypes.c_int.in_dll(lib, name)

Key = SimpleNamespace()

initialized = False

def _init():
    global initialized    

    if initialized: return
    lib.initialization()
    for ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
        setattr(Key, ch, _get_evt_cst(f"KEY_{ch}"))
    Key.escape = _get_evt_cst("KEY_ESCAPE")
    Key.space = _get_evt_cst("KEY_SPACE")
    Key.arrow_up = _get_evt_cst("KEY_UP")
    Key.arrow_down = _get_evt_cst("KEY_DOWN")
    Key.arrow_right = _get_evt_cst("KEY_RIGHT")
    Key.arrow_left = _get_evt_cst("KEY_LEFT")

    initialized = True


_init()