<div dir="ltr"><div>I see. I was wanting to get gamepad input to control a game. I naively assumed this was serial, Daniel's reply suggested the gamepad might be a HID device which I haven't checked yet.<br><br>"how are you NOT going to mess that up?" coincides with the response on <a href="http://stackoverflow.com/questions/42750491/read-a-character-input-from-erlang-without-requiring-the-return-key-pressed-from/42755503#42755503">http://stackoverflow.com/questions/42750491/read-a-character-input-from-erlang-without-requiring-the-return-key-pressed-from/42755503#42755503</a> "you are entering a world of pain you never knew existed"<br><br></div>So for now, I'm running a Cowboy server and using a c program to send characters pressed through cURL <br><br>#include<stdio.h><br>#include<stdlib.h><br><br>int main(void){<br> system ("clear");<br> int c;<br> /* use system call to make terminal send all keystrokes directly to stdin */<br> system ("/bin/stty raw");<br> while((c=getchar())!= '.') {<br> char command[100];<br> sprintf(command, "curl localhost:8080/info?%c" ,c);<br> system(command);<br> printf("\r\n");<br><br> /* type a period to break out of the loop, since CTRL-D won't work raw */<br> }<br> /* use system call to set terminal behaviour to more normal behaviour */<br> system ("/bin/stty cooked");<br> system ("clear");<br> system ("echo ok\n");<br> return 0;<br>}<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 14, 2017 at 1:16 AM, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 13/03/2017, at 7:19 AM, qp <<a href="mailto:quantumpotato@gmail.com">quantumpotato@gmail.com</a>> wrote:<br>
><br>
> How do read 1 character at a time without requiring the enter press?<br>
<br>
</span>The obvious question is "why do you want to do this"?<br>
<br>
It's actually nowhere as simple an issue as you might think.<br>
Seriously, it's not clear what "read 1 character at a time"<br>
MEANS. Do you mean<br>
- read a keycode?<br>
- read a byte?<br>
- read a possibly multibyte character?<br>
and<br>
- if the user pushes a an error or function key,<br>
sending an ESC [ .... <char> sequence, do you<br>
want just the ESC (and if so what happens to everything<br>
after it) or the whole thing<br>
- how are you going to tell the difference between ESC [ ...<br>
sent from a special key and an ESC sent from the ESC key<br>
(I've seen two approaches: don't try to distinguish, and<br>
use a timeout)<br>
and<br>
+ do you want the character to be echoed<br>
- or not<br>
+ do you want some interrupt characters to be<br>
heeded still<br>
- or not<br>
and<br>
- if there are multiple characters already buffered<br>
(from a time when the terminal was in a "cooked" mode, perhaps)<br>
and you switch to whatever character-at-a-time mode you want,<br>
what is to happen to those characters?<br>
and above all,<br>
* given that Erlang uses GNU readline or something very like<br>
it, even when calling io:get_chars/2, how are you NOT going<br>
to mess that up?<br>
<br>
Having said that,<br>
<a href="http://erlang.org/pipermail/erlang-questions/2009-November/047298.html" rel="noreferrer" target="_blank">http://erlang.org/pipermail/<wbr>erlang-questions/2009-<wbr>November/047298.html</a><br>
tells us that Joe Armstrong wrote an emacs-like editor in Erlang.<br>
<quote><br>
I wrote a simple emacs editor years ago -<br>
it's in the widgets subdirectory of<br>
<a href="http://www.sics.se/~joe/ex11/download/release-2.5.tgz" rel="noreferrer" target="_blank">http://www.sics.se/~joe/ex11/<wbr>download/release-2.5.tgz</a><br>
<br>
The only tricky part was not the emacs logic,<br>
but the screen display<br>
and catching the keystrokes and mouse events.<br>
</quote><br>
<br>
That link is dead, but <a href="https://github.com/baryluk/ex11" rel="noreferrer" target="_blank">https://github.com/baryluk/<wbr>ex11</a><br>
should work.<br>
<br>
It's not *much* of an emacs: ^A ^E ^D ^B ^F PgUp PgDn<br>
arrow keys and inserting plain characters. Call it<br>
proof-of-concept.<br>
<br>
An alternative would be to use a separate program to do this.<br>
<br>
</blockquote></div><br></div>