PDA

Click to See Complete Forum and Search --> : Get ESC character from console


Daok
Aug 13th, 2002, 10:02 AM
cin doesn't work so I think the API : ReadConsoleInput can but I cannot put it work well.

Here is what I have :

char c;
PINPUT_RECORD lpBuffer=0;
LPDWORD lpNumberOfEventsRead =0;

ReadConsoleInput(NULL,lpBuffer,1,lpNumberOfEventsRead);
c = lpBuffer.KEY_EVENT;

Daok
Aug 13th, 2002, 10:14 AM
Here is what I have but it doesn't work better :


PINPUT_RECORD lpBuffer=0;
LPDWORD lpNumberOfEventsRead =0;
ReadConsoleInput(new HANDLE,lpBuffer,1,lpNumberOfEventsRead);
char c;
c = (char)lpNumberOfEventsRead;
cout << "here : " << c << " ";

Daok
Aug 13th, 2002, 10:36 AM
..........
HANDLE hStdin;
INPUT_RECORD irInBuf[1];
hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD cNumRead;

char c;
do
{
//cin.get(c);

SetXY(8,8);

ReadConsoleInput(
hStdin, // input buffer handle
irInBuf, // buffer to read into
1, // size of read buffer
&cNumRead); // number of records read

if (irInBuf[0].EventType == KEY_EVENT)
c = irInBuf[0].Event.KeyEvent.uChar.AsciiChar;

cout << "here : " << c << " ";
..........


that work but it doesn't let me write anything in the console and it show a weird character to the screen.

Anyone know how to get ESC char and ARROW char from the console ?

Daok
Aug 13th, 2002, 12:05 PM
How can I read all character tapped in the console even ESCAPE and ARROW character ?

Daok
Aug 13th, 2002, 12:36 PM
Is there a way to get character from the console without using CIN ?

Daok
Aug 14th, 2002, 02:31 AM
I use getch() of conio.h for the moment but I am sure that it have an other way.

abdul
Aug 14th, 2002, 04:11 AM
I think you can use getchar(). Don't think it'll process ESC or ARROWS keys though.

jim mcnamara
Aug 14th, 2002, 06:26 AM
conio is just exactly what you want - console i/o.
Don't blindly assume api's are the best choice. Base C & C++ i/o calls are extremely efficient.

Daok
Aug 14th, 2002, 08:09 AM
I know but I did not want to include all conio.h when I need only getch().

jim mcnamara
Aug 14th, 2002, 08:57 PM
It's not a waste - the linker only brings in code to support what you use, not everything in an include file

Daok
Aug 15th, 2002, 07:18 PM
hummm I didn't know, cool :)