I am sure this must have been asked before, but a quick search found nothing.
How can I get the arrow/direction keys with cin in c++?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It has indeed been asked before, and the answer is that you cannot do it.
C++ has no concept of a keyboard or a console. It only knows of an opaque input data stream.
Your physical console preprocesses and buffers your keyboard activity and only sends cooked data to the program, usually line-by-line. In order to talk to the keyboard directly, you require a platform-specific terminal handling library.
On Linux, this is usually done with the
ncursesortermcap/terminfolibraries. On Windows you can usepdcurses, or perhaps the Windows API (though I’m not familiar with that aspect).Graphic-application frameworks such as SDL, Allegro, Irrlicht or Ogre3D come with full keyboard and mouse handling, too.