Thread overview
Input engine
Sep 15, 2019
Joel
Sep 15, 2019
rikki cattermole
Sep 16, 2019
Joel
Sep 16, 2019
DanielG
September 15, 2019
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.
September 15, 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
September 16, 2019
On Sunday, 15 September 2019 at 10:52:43 UTC, rikki cattermole wrote:
> 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

I was using DSFML 2.1.1[0] for keyboard input, but with the last macOS update, it just crashes my programs, (it was unstable anyway). I have my own wrapper[0] for handling key pressers. I just need to know when (a) key(s) is/are down (and what key(s)). I still want to use DSFML for other stuff (like graphics).

I've had the whole macOS crash, with trying to get Allegro working on it with code that works on Windows OS. I haven't got any SDL program working - DLangUI programs compile and work though.

[0] https://code.dlang.org/packages/dsfml
[1] https://github.com/joelcnz/JecLib
September 16, 2019
On Monday, 16 September 2019 at 02:05:37 UTC, Joel wrote:
> I was using DSFML 2.1.1[0] for keyboard input, but with the
> ...

Since you still want to use the library - have you looked upstream at the SFML project to see if they are having problems there? Might be worth trying to write a small C/C++ test program against it to see if the problem is there, or just with the D bindings.

> I've had the whole macOS crash, with trying to get Allegro working on it
> ...

I hope you are filing bug reports! That's pretty serious and they'd probably want to know about it.