How to get unbuffered keyboard input?

Dec 19, 2018 at 2:29am
I'm creating a game in the console and I want players to control their position in an array with the arrow keys. Using cin for this would require them to press enter each time they want to move.

What's the best / most effective method of getting unbuffered keyboard input? (without using cin)
Last edited on Dec 19, 2018 at 2:30am
Dec 19, 2018 at 5:50am
Which OS/Compiler are you using?
Dec 19, 2018 at 6:03am
Windows 10 / TDM-GCC
Dec 19, 2018 at 6:24am
https://docs.microsoft.com/en-us/windows/console/readconsoleinput
Along with say
GetNumberOfConsoleInputEvents function
PeekConsoleInput function.
Dec 19, 2018 at 10:39pm
looks like directinput is actually not the lowest level access for a keyboard.
Are you going to drag in the windows libraries in your program? If so the above looks like the best answer. If not, getch might do what you want, or an assembly one liner.
Last edited on Dec 19, 2018 at 10:43pm
Dec 20, 2018 at 6:26am
If you want unbuffered input from a file, you use the open system call (man 2 open). You can also use map, a more advanced syscall that allows you to directly access the kernel buffers used when reading a file, without bothering with read.
Topic archived. No new replies allowed.