Charan Chakravarthy
Charan Chakravarthy

Reputation: 21

How to read characters with out pressing enter key in c++

I am writing a small game program in c++, which requires user to press some keys from keyboard. The problem with 'cin>>' or cin.get() is that it requires user to press enter to read data into memory. So, please help me to read key strokes with out pressing enter key. I work on Linux.

Upvotes: 0

Views: 205

Answers (2)

Jonathan Wakely
Jonathan Wakely

Reputation: 171273

By default the terminal is buffered and is in "cooked mode" where individual key presses are not sent to the application immediately.

You might be able to use something like GNU readline for input, or you could use ncurses for input and output, or if you just want to receive every key as it's pressed you could put the terminal into raw mode and do everything manually using the cfmakeraw function.

Upvotes: 0

szarlih
szarlih

Reputation: 135

maybe you can use ncurses library?

Upvotes: 2

Related Questions