How to get unbuffered keyboard input?

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
Which OS/Compiler are you using?
Windows 10 / TDM-GCC
https://docs.microsoft.com/en-us/windows/console/readconsoleinput
Along with say
GetNumberOfConsoleInputEvents function
PeekConsoleInput function.
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
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.