Thread: For those who know Qbasic:inkey$ in c++

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    For those who know Qbasic:inkey$ in c++

    Is there an inkey$-like command in c++?

  2. #2
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    What does the inkey$ command do, maybe I can help you.
    none...

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    QBasic inkey$ holds any pressed keys like 'e' or 't'.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    17

    inkey$

    you would use it like this:

    a$ = inkey$
    <process on a$>

    inkey holds the current keypress. What he needs to know is how to use the termios struct to get non-canonical <sp?> input. I don't have the code off the top of my head, someone else?
    -----------------------
    R. D. Nichols, Jr.

    -Why do I have to go EVERYWHERE in this handbasket?

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    17
    This code would set the terminal to raw mode.


    code:--------------------------------------------------------------------------------
    #include <termios.h>
    #include <unistd.h>
    #include <stdio.h>
    #include <fcntl.h>

    struct termios o,
    n;
    if( tcgetattr( STDIN_FILENO, &o ) != 0 ) {
    /* error handling */
    }
    n = o;
    n.c_lflag &= ~( ICANON | ECHO );
    n.c_cc[VMIN] = 1;
    n.c_cc[VTIME] = 0;
    if( tcsetattr( STDIN_FILENO, TCSANOW, &n ) != 0 ) {
    /* error handling */
    }
    if( fcntl( STDIN_FILENO, F_SETFL, O_NONBLOCK ) == -1 ) {
    /* error handling */
    }
    --------------------------------------------------------------------------------


    Use this to make the terminal raw and nonblocking. And then you call getchar( ) at some arbitrary point - If it returns EOF, there was no key to read, otherwise it returns the key.


    code:--------------------------------------------------------------------------------int ch;
    ch = getchar( );
    if( ch != EOF ) {
    /* do something with ch */
    }--------------------------------------------------------------------------------


    And when you're done, restore the old terminal state:


    code:--------------------------------------------------------------------------------tcsetattr( STDIN_FILENO, TCSANOW, &o );




    Props to vVv, I stole his code.
    -----------------------
    R. D. Nichols, Jr.

    -Why do I have to go EVERYWHERE in this handbasket?

Popular pages Recent additions subscribe to a feed