View Full Version : Unix and keystrokes
Amit Agrawal
07-03-2000, 11:25 PM
I want to write a program in C++ which shall run on linux. I want to capture the keystokes as the key is pressed without the necessity of hitting return/enter.
What is the function I should use?
------------------
In God we trust
From all others we demand data
Paul Victorey
07-05-2000, 11:37 AM
Either getc() or getch() should work, I believe they will read in without needing a return?
Otherwise, this problem can be tougher. Usually in C++ I use my own x86 keyboard handler so as to have more control over keys, so I'm not familiar with linux or with typical get character functions.
------------------
Paul M. Victorey
------------------
I am not responsible for any problems that may arise as a result of following my advice. This includes, but is not limited to, computer failure, loss of data, nuclear war, famine, boils, no clean laundry, your daughter running off with a biker gang, or armageddon. Take my advice at your own risk.
Amit Agrawal
07-10-2000, 03:41 AM
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Paul Victorey:
Either getc() or getch() should work, I believe they will read in without needing a return?
Otherwise, this problem can be tougher. Usually in C++ I use my own x86 keyboard handler so as to have more control over keys, so I'm not familiar with linux or with typical get character functions.
<HR></BLOCKQUOTE>
Amit Agrawal
07-10-2000, 03:43 AM
The functions suggested are found only in the conio.h which is not available in UNIX env.
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Paul Victorey:
Either getc() or getch() should work, I believe they will read in without needing a return?
Otherwise, this problem can be tougher. Usually in C++ I use my own x86 keyboard handler so as to have more control over keys, so I'm not familiar with linux or with typical get character functions.
<HR></BLOCKQUOTE>
SteveD
07-19-2000, 03:55 AM
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Amit Agrawal:
I want to write a program in C++ which shall run on linux. I want to capture the keystokes as the key is pressed without the necessity of hitting return/enter.
What is the function I should use?
<HR></BLOCKQUOTE>
You can use the curses library. It has a getch() that will allow you to do this.
getc(), as suggested before, requires you to hit return, so you can't use it.
To use the curses library, see this page: http://www.ecks.org/docs/ncurses-intro.html
ProgramKid
08-05-2000, 05:48 PM
<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Amit Agrawal:
I want to write a program in C++ which shall run on linux. I want to capture the keystokes as the key is pressed without the necessity of hitting return/enter.
What is the function I should use?
<HR></BLOCKQUOTE>
Use cin.get. It is in iostream.h
vBulletin® v3.7.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.