Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read single keys?

Status
Not open for further replies.

Bertv100

Programmer
Apr 27, 2000
204
BE
(g++ under Mandrake Linux)

How can I read a single character without it being echoed on screen (like Turbo Pascal's ReadKey function); and what are the scancodes for special keys such as F1..F12, Insert, Delete, Home, End, Arrows, etc.

How can I move the cursor on screen and which functions allow me to change text color and background color?

Are there functions to clear the entire screen (TP: ClrScr) and to clear the line at the cursor's right (TP: ClrEol)?
Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Have a look at the man page on curses. It probably has most of the answers to your questions.

Warning: DO NOT use curses with STL. It plays havoc with the template definitions and it just wont compile. If you are using both STL and curses, use the adapter/facade pattern as a front-end to curses.
 
hi,

many years ago, I have built a video aapplication,
and I had to resolve this problem.

You have to define a function in your appl. say GETKEY.

Inside it you have to precall a normal getchar by the
mitic ioctl: it is not easy, but it is very interesting.

the concept is:
- save current I/O parms in a var
- set them as I want ( noecho, just 1 char, timeout )
- restore saved values

ioctl has almost 3 parameters:

1: the channel you are modifying ( stdin in your case )
2: which operation : GET or SET
3: a structure pointer to pass parameters.

-------------------------------

About scancode, probably those keys return more than 1 char:
you have to build your program step by step:

get1()
{
ioctl GET
ioctl SET
c=getchar
ioctl SET
return c
}

GETKEY()
{
char c=get1();

if( c>32 && c<126 ) // normal char
reurn c ;

if( c==ESCAPE ) //
c=get1()

swtich( c )
{
case 1: return F1 ;
case 2: return F2 ;
default return ERROR
}
return ERROR ;

}

You have to discover the scan code by which begin
the Function key (may be Esc (27dec) or 0 , depends
from the terminal, the OS and so on.
You have to discover how many chars the keyboard sends
when you press F12 : may be 1,2 or 3.

Warning: this is a &quot;home-made&quot; method: it is not portable
from an OS to another and from a terminal to another.


bye
 
You could also save the current ostream (cout), create a new ostream asigned to (cout), and then save back the old ostream... Granted that they would have to type more than ONE char (they'd have to press enter after), but it should work... even if it isn't pretty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top