键盘的方向键问题?

yuucyf 2005-12-22 01:46:06
请问怎么判断是否按了键盘上的方向键呀?
如:
-> , <- ,... ;

该怎么判断?
...全文
167 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuucyf 2005-12-23
  • 打赏
  • 举报
回复
OK!
问题解决!!!
thomaslw 2005-12-23
  • 打赏
  • 举报
回复
VK_UP....要判断的同时把数字键区的按键也加上吧(检查NUMLOCK的状态)
IonEdge 2005-12-22
  • 打赏
  • 举报
回复
#include<iostream>
#include<stdlib.h>
#include<conio.h>
#define VK_LEFT 75
#define VK_UP 72
#define VK_RIGHT 77
#define VK_DOWN 80
using namespace std ;

int main()
{
char z ;
int a ;

z = getch() ;
z = getch();
a = int(z) ;
switch(a)
{
case VK_LEFT :
{
cout << "is turn left!" << endl ;
break ;
}
case VK_UP :
{
cout << "is turn UP!" << endl ;
break ;
}
case VK_RIGHT :
{
cout << "is turn RIGHT!" << endl ;
break ;
}
case VK_DOWN :
{
cout << "is turn DOWN!" << endl ;
break ;
}
default:
{
cout << "jjj"<<endl;
cout << a << endl;
break;
}
}
system("pause") ;
return 0 ;
}

dte99 2005-12-22
  • 打赏
  • 举报
回复

The _getch function reads a single character from the console without echoing. _getche reads a single character from the console and echoes the character read. Neither function can be used to read CTRL+C. When reading a function key or an arrow key, _getch and _getche must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.

估计可能是这个原因,注意最后一句。
IonEdge 2005-12-22
  • 打赏
  • 举报
回复
#define VK_LEFT 52
#define VK_UP 56
#define VK_RIGHT 54
#define VK_DOWN 50
用数字键的小键盘
yuucyf 2005-12-22
  • 打赏
  • 举报
回复
没分怎么就没什么人回答呢???
yuucyf 2005-12-22
  • 打赏
  • 举报
回复
我这样试了下好象不行呀?

#include<iostream>
#include<stdlib.h>
#include<conio.h>
#define VK_LEFT 37
#define VK_UP 38
#define VK_RIGHT 39
#define VK_DOWN 40
using namespace std ;

int main()
{
char z ;
int a ;

z = getch() ;
a = int(z) ;
switch(a)
{
case VK_LEFT :
{
cout << "is turn left!" << endl ;
break ;
}
case VK_UP :
{
cout << "is turn UP!" << endl ;
break ;
}
case VK_RIGHT :
{
cout << "is turn RIGHT!" << endl ;
break ;
}
case VK_DOWN :
{
cout << "is turn DOWN!" << endl ;
break ;
}
}
system("pause") ;
return 0 ;
}

dragonzxh 2005-12-22
  • 打赏
  • 举报
回复
#define VK_LEFT 0x25
#define VK_UP 0x26
#define VK_RIGHT 0x27
#define VK_DOWN 0x28
/* VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
/* VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
没试过~~~~。。。。楼主自己试试看呢

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧