将击键转换为c中的ascii等价物 [英] converting keystrokes into ascii equivalent in c
问题描述
嘿,
我正在开发一个应用程序,我想对各种击键执行一些操作,根据我的理解,这可以通过查找按下的键的ascii代码来实现。 br />
所以在c中是否有任何功能来确定按下的键的ascii代码...
我遇到了某些功能,如getch,getche和getchar,但它们似乎都没有达到我的目的......
hey,
I am working on an application where I would like to perform some actions on various keystrokes,from my understanding,this is possible by finding out the ascii code of the key pressed.
so Is there any funtion in "c" to determine the ascii code of the key pressed...
I came across certain functions like "getch","getche" and "getchar"but none of them seem to serve my purpose...
const int size=50;
char name[size];//any character array
unsigned int char
for(int i=0;i<size;i++)
{
ch=getch();
scanf("%s",Name[i]);
if(ch==33)//ascii code of "Esc"
{
Name[i]=''\0'';
}
break;
}
推荐答案
getch,getche和getchar但它们似乎都没有达到我的目的......
getch","getche" and "getchar"but none of them seem to serve my purpose...
实际上所有这些都返回 ASCII
输入字符的代码(那你的目的是什么?)。
[更新]
请注意十进制 ESC
代码 27
。您在十进制常量中使用其八进制值(在 C
中,八进制常量必须 0-prefixed
,即 033
)。
无论如何拦截 ESC
很棘手(我的控制台应用程序上有 146
)。我建议你使用''q''
或其他)。
[/ Update]
顺便说一下,你的代码看起来有点乱。
Actually ALL of them return the ASCII
code of the input character (So what is your purpose?).
[Update]
Please note the decimal ESC
code is 27
. You are using its octal value in a decimal constant (in C
an octal constant must be 0-prefixed
, that is 033
).
Anyway intercepting ESC
is tricky (I got 146
on my console application). I suggest you to use ''q''
or something else).
[/Update]
By the way, your code looks a bit messy.
这篇关于将击键转换为c中的ascii等价物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!