Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Walnut::Input to support key callbacks #52

Open
jchionh opened this issue Jul 23, 2023 · 1 comment
Open

Walnut::Input to support key callbacks #52

jchionh opened this issue Jul 23, 2023 · 1 comment

Comments

@jchionh
Copy link

jchionh commented Jul 23, 2023

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;
@jchionh
Copy link
Author

jchionh commented Jul 23, 2023

Proposed PR:
#53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant