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?
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
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.
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
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.
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)
Oh, and you must add this:
at the beginning of your main and:Code:oldKeybInt = getvect (KEYB_INT); // Re-direct ISR. setvect (KEYB_INT, newKeybInt);
at the end.Code:setvect (KEYB_INT, oldKeybInt); // Replace old keyboard interrupt.
Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)
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..