gotoxy and using arrows?

This is a discussion on gotoxy and using arrows? within the C++ Programming forums, part of the General Programming Boards category; I tried a code that had something like: ... #define left 'K' ... ... if(getch() == left) { gotoxy(x, y); ...

  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: trifaze_mattu@lycos.com

    ---------------------------------
    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,796
    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: trifaze_mattu@lycos.com

    ---------------------------------
    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,796
    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
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    To get the actual keys, you need to get the scan codes. Look at the attatchment, this only works in DOS.
    Attached Files Attached Files
    MSVC++ 6.0

  6. #6
    Budding Synth Programmer samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Trefforest
    Posts
    368
    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.
    MSVC++ 6.0

  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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21