I am making a simple 2d game in the terminal, and I have been wondering how I could get stdin without having to return. So, instead of the user having to press w\n (\n for return), they would just press ‘w’ and it would go forwards.
scanf, gets, and getchar cannot do this, but I have seen it be done before in programs such as Vi. How would I achieve this?
I am making a simple 2d game in the terminal, and I have been
Share
You need to set your terminal to non-canonical mode. You can use functions like tcsetattr, and tcgetattr to set and get terminal attributes. Here is a trivial example:
For more info about these functions, see glibc documentation. Especially this part.