#include #include #include f32 kf_deadzone = 0.2f; struct _kf_inputbinds kf_inputbinds = { .count = 1, }; kf_inputbind_t kf_addinput(char *id, KeyboardKey key, KeyboardKey alt, MouseButton mouse, GamepadButton gamepad, GamepadAxis axis) { kf_inputbind_t i = kf_inputbinds.count; if (i >= KF_INPUTBIND_MAX) { KF_THROW("max keybind count is 255"); return -1; /* unreachable */ } kf_inputbinds.count++; // kf_logdbg("add keybind: %d: %s (k=%d a=%d m=%d g=%d x=%d)", i, id, key, alt, mouse, gamepad, axis); kf_inputbinds.id[i] = id; kf_inputbinds.key[i] = key; kf_inputbinds.alt[i] = alt; kf_inputbinds.mouse[i] = mouse; kf_inputbinds.gamepad[i] = gamepad; kf_inputbinds.axis[i] = axis; return i; } kf_inputbind_t kf_getinput(char *id) { for (int i = 0 ; i < KF_INPUTBIND_MAX ; i++) { if (strcmp(id, kf_inputbinds.id[i]) == 0) { return i; } } return KF_INPUTBIND_NONE; } int kf_checkkeypress(kf_inputbind_t id) { return (kf_inputbinds.key[id] != KEY_NULL && IsKeyPressed(kf_inputbinds.key[id])) || (kf_inputbinds.alt[id] != KEY_NULL && IsKeyPressed(kf_inputbinds.alt[id])); } int kf_checkkeyrelease(kf_inputbind_t id) { return (kf_inputbinds.key[id] != KEY_NULL && IsKeyReleased(kf_inputbinds.key[id])) || (kf_inputbinds.alt[id] != KEY_NULL && IsKeyReleased(kf_inputbinds.alt[id])); } int kf_checkkeydown(kf_inputbind_t id) { return (kf_inputbinds.key[id] != KEY_NULL && IsKeyDown(kf_inputbinds.key[id])) || (kf_inputbinds.alt[id] != KEY_NULL && IsKeyDown(kf_inputbinds.alt[id])); } int kf_checkkeyup(kf_inputbind_t id) { return (kf_inputbinds.key[id] != KEY_NULL && IsKeyUp(kf_inputbinds.key[id])) || (kf_inputbinds.alt[id] != KEY_NULL && IsKeyUp(kf_inputbinds.alt[id])); } int kf_checkmousepress(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonPressed(kf_inputbinds.mouse[id]); } int kf_checkmouserelease(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonReleased(kf_inputbinds.mouse[id]); } int kf_checkmousedown(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonDown(kf_inputbinds.mouse[id]); } int kf_checkmouseup(kf_inputbind_t id) { return kf_inputbinds.mouse[id] != MOUSE_BUTTON_UNKNOWN && IsMouseButtonUp(kf_inputbinds.mouse[id]); } int kf_checkgamepadpress(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonPressed(0, kf_inputbinds.gamepad[id]); } int kf_checkgamepadrelease(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonReleased(0, kf_inputbinds.gamepad[id]); } int kf_checkgamepaddown(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonDown(0, kf_inputbinds.gamepad[id]); } int kf_checkgamepadup(kf_inputbind_t id) { return kf_inputbinds.gamepad[id] != GAMEPAD_BUTTON_UNKNOWN && IsGamepadButtonUp(0, kf_inputbinds.gamepad[id]); } float kf_getgamepadaxis(kf_inputbind_t id) { return kf_inputbinds.axis[id] != GAMEPAD_AXIS_UNKNOWN ? GetGamepadAxisMovement(0, kf_inputbinds.gamepad[id]) : 0; } int kf_checkinputpress(kf_inputbind_t id) { return kf_checkkeypress(id) || kf_checkmousepress(id) || kf_checkgamepadpress(id); } int kf_checkinputrelease(kf_inputbind_t id) { return kf_checkkeyrelease(id) || kf_checkmouserelease(id) || kf_checkgamepadrelease(id); } int kf_checkinputdown(kf_inputbind_t id) { return kf_checkkeydown(id) || kf_checkmousedown(id) || kf_checkgamepaddown(id); } int kf_checkinputup(kf_inputbind_t id) { return kf_checkkeyup(id) || kf_checkmouseup(id) || kf_checkgamepadup(id); }