Walnut::Input to support key callbacks
jchionh opened this issue · comments
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;
Proposed PR:
#53