Skip to content

Walnut::Input to support key callbacks #52

@jchionh

Description

@jchionh

Existing Input.cpp class only supports checking of if key is pressed down.

This is a proposal to add support for callbacks via:
https://www.glfw.org/docs/3.3/input_guide.html#input_key

Additions to the Input class:

// this method will set a private KeysCallback() function by glfwSetKeyCallback(window, KeysCallback);
static void InitKeysCallBack();

// this method adds func to a unordered_map using KeyCode as the key
static void SetKeyCallback(KeyCode keycode, std::function<void()> func);

// this function gets called by GLFW when a key is pressed, and on keyboard's repeat timing
// we will lookup the unordered_map to see if a std::function is set in the map, if it is, invoke it.
void KeysCallback(GLFWwindow* window, int key, int scancode, int action, int mods);

// this is the undorderd_map that stored custom key callbacks.
static std::unordered_map<int, std::function<void()>> KEY_CALLBACK_MAP;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions