I'm trying to code a basic video-game and would like the input to be entered from the keyboard. Therefore, I need to read the characters on the standard input as they are produced. Because of the buffering, io:get_chars, io:fread will return only after the return key is pressed.
The point of the project is not to make a real-life game, it is just a way of learning about Erlang. Therefore performance is not an issue.
EDIT: This project seems to offer the feature I am looking for. If I am not mistaken, though, a part of the code is written in C and sends the characters to the Erlang part via message passing. Is there an alternative, native to Erlang, to this approach, or is this the only approach that would work?
Generally speaking, reading from STDIN is not the way you want to go when it comes to processing keyboard input for a game. You want to be able to read the state of keys at any given moment.
Take a look at wx (and the reference manual)
It's an Erlang interface to the wxWidgets library, and includes interfaces for handling various inputs, including keyboards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With