I need to detect a keystroke, without the user pressing enter. What’s the most elegant way?
I.e. If the user hits the letter Q, without pressing enter, the program does something.
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.
In unix/posix, the standard way of doing this is to put the input into non-canonical mode with tcsetattr:
See the termios(3) man page for more details (and probably more information than you wanted to know).