06-26-04 03:11 PM
calle8787@hotmail.com (Calle) writes:
> My code look like this:
>
> #include <iostream>
> #include <stdio.h>
>
> using namespace std;
>
> int main()
> {
> int key;
> key = getchar();
>
> cout << key << endl;
>
> if (key == 333)
> cout << "You pressed the rightarrow key!" << endl;
> }
>
> The problem is that if I press on of the arrow keys, the only thing I
> get is 27, which is ESC.
>
> Is it possible to use the arrow keys, and if it is, how do I use them?
Do you use a function named getkey? No. You're using a function getchar.
So you're getting a character, not a key!
Some of the problems with keys are that:
- each terminal has it's own codes for keys,
- they're not useful in batch processing (so a unix program written
to behave interactively with some terminal key can't work from
scripts, check for example all these people asking for scripting
ftp(1)! (And it does not even use "keys"!).
- etc.
But if you really need to, either you could use curses (or ncurses)
where there are functions to handle keys.
--
__Pascal Bourguignon__ http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein
[ Post a follow-up to this message ]
|