Linux, X11: Enter key not seen at Char callback

I added code in the Key callback to emit an event for Char 10, looks like this:


However this does not support key repeat.

I’m not sure if you looking for help with dear imgui or with GLFW?

The enter key is already handled by imgui’s widgets, see the demo multi-line text input widget for an example.

In GLFW the enter key is not sent to the char callback. I think it could be argued that it should be (perhaps optionally), as a text file can include return characters. However at the moment the intention is that you should handle GLFW_KEY_ENTER yourself via the key callbacks or glfwGetKey().

if you need to implement repeat then you need to add code to do this. For an example see https://github.com/glfw/glfw/blob/master/src/input.c#L260-L279

1 Like

That code is a horrible example.

  1. It doesn’t implement key repeat it detects key repeat in the key callback, from what I understand that is a bug in the glfw driver.
  2. The repeated variable can be removed by moving the test a few lines down. So it’s not ideal for anyone to copy that code.

Implementing key repeat in the key callback is a bad idea for a number of reasons most importantly configuration. We don’t wanna present the user with an interface that has a different key repeat delay or rate for the enter key.

As I mentioned earlier I think there’s a case for passing the return through to the char callback. If you’d like to request this the relevant place is the GLFW issue tracker and I’d be happy to post an issue if you don’t have a Github account. Currently the codepoints for carriage return and line feed are filtered out by https://github.com/glfw/glfw/blob/master/src/input.c#L292

Re the ‘example’:

  1. It was a bad section of code for me to link to without explanation, as it’s not an example of how to implement what you desire but shows how the GLFW code detects key repeats. I should instead have explained more about GLFW_REPEAT.
  2. The test can’t be moved further down without further logic as when stickyKeys is set the action stored in the key table needs to be GLFW_PRESS and not GLFW_REPEAT.

If you implement this yourself you don’t have to worry about getting the wrong repeat interval, as the key events are sent at the rate as char events (key events are translated into char events by OS specific functions). So if you can handle GLFW_REPEAT in your key callback in the same way as GLFW_PRESS you should get the same result as if it was handled by glfwInputChar.