int keyState = 0;
enum
{
ARROW_UP = 256 + 72,
ARROW_DOWN = 256 + 80,
ARROW_LEFT = 256 + 75,
ARROW_RIGHT = 256 + 77
KEY_ESC = 27,
};
#define KEY_UP 1<< 0
#define KEY_DOWN 1<< 1
#define KEY_LEFT 1<< 2
#define KEY_RIGHT 1<< 3
#define KEY_ESC 1<< 4
int getKeyCode(int keyCode)
{
switch (keyCode)
{
case ARROW_UP:
return KEY_UP;
break;
case ARROW_DOWN:
return KEY_DOWN:
break;
case ARROW_LEFT:
return KEY_LEFT:
break;
case ECS:
return KEY_ESC:
break;
default:
break;
}
}
int getKeyStates(void)
{
return keyState;
}
void clearKeyStates(void)
{
keyState = 0;
}
int keyDown(int keyCode)
{
return keyState & keyCode;
}
void keyPressed(int keyCode)
{
int key = getKeyCode(keyCode);
keyState |= key;
}
int getCode(void)
{
int ch = getch();
if(ch == 0 || ch == 224)
ch = 256 + getch();
return ch;
}
本想给你加个 按键接口,可惜加不进去, 既然写了就发出来吧,或许对你有帮助
[ 本帖最后由 BlueGuy 于 2010-10-24 15:20 编辑 ]
enum
{
ARROW_UP = 256 + 72,
ARROW_DOWN = 256 + 80,
ARROW_LEFT = 256 + 75,
ARROW_RIGHT = 256 + 77
KEY_ESC = 27,
};
#define KEY_UP 1<< 0
#define KEY_DOWN 1<< 1
#define KEY_LEFT 1<< 2
#define KEY_RIGHT 1<< 3
#define KEY_ESC 1<< 4
int getKeyCode(int keyCode)
{
switch (keyCode)
{
case ARROW_UP:
return KEY_UP;
break;
case ARROW_DOWN:
return KEY_DOWN:
break;
case ARROW_LEFT:
return KEY_LEFT:
break;
case ECS:
return KEY_ESC:
break;
default:
break;
}
}
int getKeyStates(void)
{
return keyState;
}
void clearKeyStates(void)
{
keyState = 0;
}
int keyDown(int keyCode)
{
return keyState & keyCode;
}
void keyPressed(int keyCode)
{
int key = getKeyCode(keyCode);
keyState |= key;
}
int getCode(void)
{
int ch = getch();
if(ch == 0 || ch == 224)
ch = 256 + getch();
return ch;
}
本想给你加个 按键接口,可惜加不进去, 既然写了就发出来吧,或许对你有帮助
[ 本帖最后由 BlueGuy 于 2010-10-24 15:20 编辑 ]
我就是真命天子,顺我者生,逆我者死!