Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get keypress event in console

Tags:

c

events

I want to get on_key_press_event without pressing Enter. And of course I need the character code. Is there solution?

like image 829
Hexogen Avatar asked Feb 20 '13 05:02

Hexogen


2 Answers

I recommend having a read through here. I think

getchar()

might be what you're after.

EDIT: In fact possibly

#include <conio.h>
_getch()

would work better for you as it does not require the end of line character (enter button to be pressed). For windows refer to this and for unix systems this seems to be included in the curses library.

Hope this helps!

like image 54
Anthony Clark Avatar answered Oct 11 '22 07:10

Anthony Clark


There's no cross-platform way to do unbuffered input from stdin. You can use curses if you're on a Unix-based distribution. On Windows you can use getch.

like image 37
Simon Broadhead Avatar answered Oct 11 '22 05:10

Simon Broadhead