注册 登录
编程论坛 C语言论坛

求助: 键盘 按键编码 为什么是重码?

追梦人zmrghy 发布于 2022-08-18 22:28, 1174 次点击
求助: 键盘 按键编码  F1~~F10 为什么是重码?

程序代码:
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
    char key = 0;
    while(1)
    {
        key = _getch();
        if(key != 0)
        {
            if(key > 0)
                printf("key = %d\n",key);
            else
                printf("key = %d  ",key);
            key = 0;
        }
    }

    return 0;
}


只有本站会员才能查看附件,请 登录

7 回复
#2
rjsp2022-08-18 22:55
重码?自己创造的名词吧
不但会起名字,还会改返回类型。明明是int,你把它改为char
还改返回值含义, if(key != 0)

https://docs.
When reading a function key or an arrow key, each function must be called twice; the first call returns 0 or 0xE0, and the second call returns the actual key code.
#3
追梦人zmrghy2022-08-19 03:53
回复 2楼 rjsp
_getch()
不是获取 一个字符吗?
什么时候,成了 int类型了呀???
#4
追梦人zmrghy2022-08-19 04:14
以下是引用rjsp在2022-8-18 22:55:39的发言:

重码?自己创造的名词吧
不但会起名字,还会改返回类型。明明是int,你把它改为char
还改返回值含义, if(key != 0)

https://docs.



只有本站会员才能查看附件,请 登录


int 类型也是一样呀。 224  换成 char 就是 -32  
F1 和 ';' 重码
F2 和 '<' 重码
F3 和 '=' 重码
F4 和 '>' 重码
F5 和 '?' 重码
F6 和 '@' 重码
F7 和 'A' 重码
F8 和 'B' 重码
F9 和 'C' 重码
F10 和 'D' 重码

#5
rjsp2022-08-19 08:37
......

程序代码:
#include <iostream>
#include <conio.h>
using namespace std;

int main( void )
{
    for( ; ; )
    {
        int ch1 = _getch();

        if( ch1==0x00 || ch1==0xE0 )
        {
            int ch2 = _getch();

            printf( "key = { %d, %d }\n", ch1, ch2 );
        }
        else
            printf( "key = { %d }\n", ch1 );
    }
}
#6
追梦人zmrghy2022-08-19 10:38
回复 5楼 rjsp
只有本站会员才能查看附件,请 登录



终于,知道区别了。
当代码执行到 key = _getch() 时,
只要没有按键输入,程序就一直等待,不再向下执行了。。。。

是这样理解吗???
#7
纯蓝之刃2022-08-25 16:01
回复 5楼 rjsp
这个00和e0是哪个规范上这么定义的?如果是linux系统,按键也是这么定义的么?
#8
rjsp2022-08-25 16:07
回复 7楼 纯蓝之刃
_getch 是M$私有的函数,linux上没有
https://docs.
1