Results 1 to 11 of 11

Thread: Get ESC character from console

  1. #1

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362

    Get ESC character from console

    cin doesn't work so I think the API : ReadConsoleInput can but I cannot put it work well.

    Here is what I have :
    PHP Code:
    char c;
            
    PINPUT_RECORD lpBuffer=0;
            
    LPDWORD lpNumberOfEventsRead =0;

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

  2. #2

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Here is what I have but it doesn't work better :

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

  3. #3

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    PHP Code:
    ..........
        
    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)
                
    irInBuf[0].Event.KeyEvent.uChar.AsciiChar

            
    cout << "here :           " << << "        ";
    .......... 
    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 ?

  4. #4

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    How can I read all character tapped in the console even ESCAPE and ARROW character ?

  5. #5

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Is there a way to get character from the console without using CIN ?

  6. #6

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    I use getch() of conio.h for the moment but I am sure that it have an other way.

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I think you can use getchar(). Don't think it'll process ESC or ARROWS keys though.
    Baaaaaaaaah

  8. #8
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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.

  9. #9

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    I know but I did not want to include all conio.h when I need only getch().

  10. #10
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    It's not a waste - the linker only brings in code to support what you use, not everything in an include file

  11. #11

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    hummm I didn't know, cool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width