www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Input engine

reply Joel <joelcnz gmail.com> writes:
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.
Sep 14 2019
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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
Sep 15 2019
parent reply Joel <joelcnz gmail.com> writes:
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
Sep 15 2019
parent DanielG <simpletangent gmail.com> writes:
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.
Sep 15 2019