Home > Back-end >  Getch () to obtain the direction key, how to feel the abscissa is the direction?
Getch () to obtain the direction key, how to feel the abscissa is the direction?

Time:10-27

XP TC compiler
 
The main ()
{

Char c [4];
Int y=5;
Int x=5;
While (1)
{
CLRSCR ();
Gotoxy (x, y);
Printf (" * ");
Gotoxy (x, y);

Gotoxy (50, 10);
Printf (" x=y=% d % d ", x, y);

C [0]=getch ();
If (c [0]==0 x4b)/* */left
{
X++;
}
Else if (c [0]==0 x4d)/* right */
{
X -;
}
Else if (c [0]==0 x48)/* * up/
{
Y -;
}
Else if (c [0]==0 x50)/* */down
{
Y++;
}
If (c [0]=='0')
{
break;
}
If (c [0]=='1')
{
X=5;
Y=5;
}


}
}



TC console should be + + 80 * 25 to left, to the right should be - and why is the opposite here?

CodePudding user response:

Give you a few procedures can see
The first:
 
#include
#include

using namespace std;

Int main () {
Char ch1;
Ch1=getch ();
cout <"Just input is:" & lt; return 0;
}

Write this is getch usage
 
#include
#include

using namespace std;

Int main () {
Char ch1;
Ch1=getch ();
cout <"Just input is:" & lt; Ch1=getch ();
cout <"Just input is:" & lt; return 0;
}

This is getch read the direction key



-- -- -- -- -- -- --
This is the key direction of judgment (basically see the)
 
#include
#include
#include
using namespace std;


Void keyTest () {
Char ch1;
While (true)
{
Ch1=getch ();
Cout//press a key, returns two values, the first is the 224
The switch (ch1) {
Case: 72
cout <"Moving up" & lt; break;
Case: 80
cout <"Move down" & lt; break;
Case: 75
cout <"Mobile" left & lt; break;
Case: 77
cout <"To the right" & lt; break;
}
}
}
Int main () {
KeyTest ();
}

Must understand the knot stickers to
Click on the "post, click on the average to points, the following stickers to have a blue, the point!
I very want to points
  • Related