Skip to content
Advertisement

C++ | How to get input from the arrow keys with Linux

I’m super new to C++ and was wanting to add arrow key functionality to my snake game. I’ve been scouring the Internet trying to find a way to do this without “conio.h” as I am using Linux. How would I go about doing this and can I get some example code?

Thank you!

Advertisement

Answer

You’d be best off using ncurses – just google for some tutorials to get yourself started. It can do simple things like clear the screen, get the terminal dimensions, position the cursor at arbitrary coordinates, write text in arbitrary colours, and yes – read characters from the keyboard without waiting for enter to be pressed. Enjoy your project!

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement