如何检测时删除键是pssed键盘上$ P $? [英] How to detect when the delete key is pressed on the keyboard?
本文介绍了如何检测时删除键是pssed键盘上$ P $?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想,当<大骨节病>删除骨节病>键pressed一定的函数被调用。
我怎样才能做到这一点使用残培()
如果可能的话或其他一些嵌套的残培()
电话?
I want that when the Del key is pressed a certain function is called.
How can I achieve that using getch()
if possible or otherwise some nested getch()
calls?
推荐答案
功能 _getch()
返回一个越狱的光标和页面控制键的值。对于键盘和功能键,也就是 0
其次是关键code,对于其他按键,它是 224
其次是关键code。
The function _getch()
returns an "escaped" value for cursor and page control keys. For the keypad and the function keys, that is 0
followed by the key code, for other keys it is 224
followed by the key code.
#include <stdio.h>
#include <conio.h>
#define ESC 27
#define ESC1 0
#define ESC2 224
int main()
{
int d=-1, e=-1;
printf("Press a key (Esc to quit)\n");
do {
d = _getch();
if (d == ESC1) {
e = _getch();
printf("%d %d\n", d, e);
} else if (d == ESC2) {
e = _getch();
printf("%d %d\n", d, e);
} else {
printf("%d\n", d);
}
} while (d != ESC);
return 0;
}
运行程序和pressing三个键删除,德尔(键盘),Esc键产生输出
Running the program and pressing three keys Delete, Del(keypad), Esc produces the output
Press a key (Esc to quit)
224 83
0 83
27
当然,数字锁定键必须关闭。
Of course, Numlock must be Off.
这篇关于如何检测时删除键是pssed键盘上$ P $?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文