On Wednesday, 11 February 2015 at 18:13:10 UTC, Paul wrote:
How do I get/process input?

Construct the real time input struct outside your loop then use getch if you're only interested in the core keyboard ascii stuff or nextEvent if you want everything.

The esc key, in particular, is considered a non-character key event by terminal.d, so it will not be there on a simple call to getch(). (this might have been a mistake but is the way it is)

Search the code for "void handleEvent" to see an example function. There's various event types you can react to and to get the info, you do

auto specialized_event = generic_event.get!(InputEvent.Type.TYPE HERE);

and look at the members. character event has ev.character. noncharacter event has ev.key which is an enum, defined on line 2057.

PasteEvent doesn't work perfectly so dont' rely on it. MouseEvent, if you opt into them, has buttons, x, y, and modifierState which might be available.

See the source for each struct to see more.



If you're happy with keys from the middle part of the keyboard, getch is the easiest way though, they are sent as simple dchars.

You can also fetch lines at a time with terminal.getline (it is on terminal rather than real time input because it is still conceptually line buffered (though the implementation turns that off to allow editing)).

Reply via email to