Input engine

rikki cattermole rikki at cattermole.co.nz
Sun Sep 15 10:52:43 UTC 2019


On 15/09/2019 12:16 PM, Joel wrote:
> What is a good keyboard input handler or so? Just need one that picks up 
> that a key is down, but not like a word processor.

Are you referring to when you hold down a key and multiple characters 
gets added to the text area?

If so, this feature is called auto-repeat and is implemented by the 
kernel on input from keyboard.

This is easily detected for Windows and can be disabled with X11.

Windowing libraries like GLFW offer telling you if an event was an 
auto-repeat GLFW_REPEAT[0]. SDL[1] has it too under the repeat field, 
and so does Allegro in the event ALLEGRO_EVENT_KEY_CHAR[2].

If you have a windowing library that forces auto-repeat on you, then you 
can use a map (with a lookup table to optimize for ASCII as that will be 
mostly what you will get with it) to check if the key is currently down.

If you have a windowing library that forces auto-repeat to be off, then 
you can use a map (with a lookup table to optimize for ASCII) and then 
use a timer and trigger your own internal to program auto repeat event.

[0] https://www.glfw.org/docs/latest/group__input.html
[1] https://wiki.libsdl.org/SDL_KeyboardEvent
[2] https://www.allegro.cc/manual/5/ALLEGRO_EVENT


More information about the Digitalmars-d-learn mailing list