Question about glfw dynamic key binds


I’ve been looking around to set up dynamic keybinds for a game, and I not sure how it ought to be configured.

At the moment I have the following (I’m using dear imgui).

In imgui, I can detect when I have clicked a button. That button signifies that I want to set a keybind. But how do I capture the next key pressed (after I have clicked the button) in a glfw window?

There is a key callback method I have created, but that key callback method has no idea whether or not I have clicked the button in imgui previously; it simply responds when I have pressed a key.

I was thinking about having a boolean check in my callback method, which I would set when I click the button so that the callback method would know whether or not the keypress should be used in a keybind.

Are there any better approaches to this?

Thank you.

This is more of a general application structure question than a GLFW one, but I can give you some ideas of what I would do.

In general I’d not use a boolean state here, as you likely have more than one keybinds. Instead you might use something like this enum:

enum eKeyBindToSet
    eKeyBindToSet_None    = 0,

Or use a structure with a boolean for ‘setting’ and then an enum for which keybind to set.

Does that help?

1 Like

Thanks, that is actually genuinely really helpful!

I was just asking to see if there is any generally agreed-upon application structure for dynamic keybinds in glfw, but it appears that the way to go is to just have some sort of indicator in your key callback that the pressed key is to be used for a keybind.

I will try this out in my application then.