Thread: gotoxy and using arrows?

  1. #1
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question gotoxy and using arrows?

    I tried a code that had something like:


    ...

    #define left 'K'
    ...

    ...

    if(getch() == left)
    {
    gotoxy(x, y);
    }

    ...

    This code doesn't seem to work for me. What do I do?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Here's an insanely simple example, use gotoxy and then redraw the menu. But use an algorithm instead of what I used for this toy program.
    Code:
    #include <iostream>
    #include <conio.h>
    using namespace std;
    
    int main ( void )
    {
      cout << "*" << " Choice 1" << endl;
      cout << "  Choice 2" << endl;
      cout << "  Choice 3" << endl;
    
      char ch;
      ch = getch();
      if ( ch == 'z' ) {
        gotoxy ( 0, 0 );
        cout << "  Choice 1" << endl;
        cout << "*" << " Choice 2" << endl;
        cout << "  Choice 3" << endl;
      }
    
      return 0;
    }
    My best code is written with the delete key.

  3. #3
    Programming is fun, mkay?
    Join Date
    Oct 2001
    Posts
    490

    Question What about...

    What if I wanted to get actual arrows, like the left or right key?
    Website(s): http://www16.brinkster.com/trifaze/

    E-mail: [email protected]

    ---------------------------------
    C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
    DirectX Version: 9.0b
    DX SDK: DirectX 8.1 SDK

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    That's system dependent, the ASCII character set doesn't specify the arrow keys, so you'll have to find out what the control commands are for them on your system. Windows programs have functions to test the value of the keys, try MSDN if you use Windows.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    To get the actual keys, you need to get the scan codes. Look at the attatchment, this only works in DOS.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  6. #6
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Oh, and you must add this:

    Code:
    oldKeybInt = getvect (KEYB_INT);		// Re-direct ISR.
    setvect (KEYB_INT, newKeybInt);
    at the beginning of your main and:

    Code:
    setvect (KEYB_INT, oldKeybInt);		// Replace old keyboard interrupt.
    at the end.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    10
    I did somthing like that in a project a while back.. used the up and down keys to move a line.. It was a selectable menue where I changed the textbackground.

    U have to know what key value the arrow returns..

Popular pages Recent additions subscribe to a feed