J
Johannes Meng
Good day,
I'm experimenting with unbuffered input at the moment. To get input I
basically use cin.get(). My problem are control sequences preceeded by an
ESC character (i.e. up, down, f-keys et cetera). They basically look like
this: <ESC><EXCODE><CODE>, where EXCODE is a number describing the type of
key pressed and CODE is the actual key. I want to be able to decide whether
ESC or such a control key was pressed. Now if I do it like this:
char code = 0, excode = 0;
code = cin.get()
if (code == 27) {
excode = cin.get();
code = cin.get();
}
, then I will have proper codes for all control keys. If ESC is pressed,
though, the user will actually have to press three times - because
cin.get() seems to wait for actual input to appear in stdin.
Now I tried stuff like
char code = 0, excode = 0;
code = cin.get()
if (code == 27 && !cin.eof()) {
excode = cin.get();
code = cin.get();
}
, but that won't work, even if there is only the ESC character in stdin.
Is there another way to determine, whether the last character was read
from stdin? Am I doing anything wrong?
Thanks alot.
I'm experimenting with unbuffered input at the moment. To get input I
basically use cin.get(). My problem are control sequences preceeded by an
ESC character (i.e. up, down, f-keys et cetera). They basically look like
this: <ESC><EXCODE><CODE>, where EXCODE is a number describing the type of
key pressed and CODE is the actual key. I want to be able to decide whether
ESC or such a control key was pressed. Now if I do it like this:
char code = 0, excode = 0;
code = cin.get()
if (code == 27) {
excode = cin.get();
code = cin.get();
}
, then I will have proper codes for all control keys. If ESC is pressed,
though, the user will actually have to press three times - because
cin.get() seems to wait for actual input to appear in stdin.
Now I tried stuff like
char code = 0, excode = 0;
code = cin.get()
if (code == 27 && !cin.eof()) {
excode = cin.get();
code = cin.get();
}
, but that won't work, even if there is only the ESC character in stdin.
Is there another way to determine, whether the last character was read
from stdin? Am I doing anything wrong?
Thanks alot.