导航:首页 > 操作系统 > linux获取键盘

linux获取键盘

发布时间:2023-02-07 18:33:58

Ⅰ 小白求问linux下怎么捕获键盘信号

int catch( int sig )
{ printf("recv del\n" );
}
int main()
{
signal( SIG_INT, catch );
while( getchar() != '\n' ) ;
return 0;
}
按回车结束程序,按Del会输出recv del。

Ⅱ linux截获键盘事件不起作用

Ⅲ Linux C语言 在多进程下 获得键盘按键

发所用语言为C..
一般的..要想学好嵌入式开发..就要两个都会..
如果只学linux,这个只是为以后从事linux服务器搭建,管理和维护等..差不多就是跟硬件打交道..
而嵌入式开发就相当于..在windows下用C,C++,C#,java等开发一样..只不过他的开发平台换成了linux...

如果想自学建议按照以下步骤:
学习步骤如下:

1、Linux 基础

安装Linux操作系统
Linux文件系统
Linux常用命令
Linux启动过程详解
熟悉Linux服务能够独立安装Linux操作系统
能够熟练使用Linux系统的基本命令
认识Linux系统的常用服务安装Linux操作系统
Linux基本命令实践
设置Linux环境变量
定制Linux的服务 Shell 编程基础使用vi编辑文件
使用Emacs编辑文件
使用其他编辑器

Ⅳ linux下循环读取键盘输入问题

scanf结束标志:
① 遇空格、“回车”、“跳格”键。
② 遇宽度结束。
③ 遇非法输入。

如果要识别空格的话 有三种方法:
1.人工加空格法:
用个变量读没有空格的单词,另一个变量存储变量,变量间用空格隔开。
2.gets()函数
这个函数用法比较危险,因为它无法判字符串的长度
如char a[10];
您的输入是abcdefggjhh dddda dddd
明显超过10个字符 而a数组只是存储了10个字符
3.继续我们的scanf函数 但是有规定只能是字母跟数字组成的字符串
scanf("%[ a-zA-Z0-9]s", str);
我们来看个例子:
#include <stdio.h>
int main()
{
char str[20];
scanf("%[ a-zA-Z0-9]s", str);
printf("%s\n",str);
return 0;
}

输入:
12a bbb ccc 123 1adb2
输出:
12a bbb ccc 123 1adb2

希望对楼主你有所帮助

Ⅳ 在LINUX下键盘编程 编写键盘应用程序 能够获取键盘按键

提供一个输入按键应用程序实例,你参考一下。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <errno.h>
#include <linux/input.h>
int main(void)
{
int buttons_fd;
int key_value,i=0,count;
struct input_event ev_key;
buttons_fd = open("/dev/input/event0", O_RDWR);
if (buttons_fd < 0) {
perror("open device buttons");
exit(1);
}
for (;;) {
count = read(buttons_fd,&ev_key,sizeof(struct input_event));
for(i=0; i<(int)count/sizeof(struct input_event); i++)
if(EV_KEY==ev_key.type)
printf("type:%d,code:%d,value:%d\n", ev_key.type,ev_key.code-1,ev_key.value);
if(EV_SYN==ev_key.type)
printf("syn event\n\n");
}
close(buttons_fd);
return 0;
}

Ⅵ 如何在嵌入式linux开发板上使用USB键盘

首先usb键盘驱动的源代码位于一下目录:
drivers/usb/input/usbkbd.c
将usb键盘驱动编译进内核:
#make menuconfig
Device Drivers--->USB support---->USB HIDBP Keyboard (simple Boot) support
(注意:有可能默认设置USB键盘驱动是不可见的,需修改当前目录下的Kconfig文件,在此不做详细介绍,Kconfig语法有待进一步熟悉:))
保存设置后,重新编译内核:
#source setenv
#make uImage
uImage生成后位于目录:arch/arm/boot/uImage;
(或者直接将usb键盘驱动编译为驱动模块,进行加载也可);

启动系统后,确定usb键盘加载到了那个设备文件,一般为/dev/input/event0设备,可通过cat命令进行确认:
#cat /dev/input/event0
操作usb键盘,会有乱码出现;
然后应用层用这个程序来获取usb键盘的输入:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
struct input_event buff;
int fd;
int read_nu;
int main(int argc, char *argv[])
{
fd = open("/dev/input/event0", O_RDONLY);
if (fd < 0)
{
perror("can not open device usbkeyboard!");
exit(1);
}
int i = 0;
printf("--fd:%d--\n",fd);
while(1)
{
while(read(fd,&buff,sizeof(struct input_event))==0)
{
;
}
//if(buff.code > 40)
printf("type:%d code:%d value:%d\n",buff.type,buff.code,buff.value);

//#if 0
//i++;
//if(i > 12)
//{
//break;
//}
//#endif
}

close(fd);
return 1;
}
运行程序后,按下A键,可见如下输出:
--fd:3--
type:1 code:30 value:1
type:0 code:0 value:0

阅读全文

与linux获取键盘相关的资料

热点内容
多媒体算法工程师camera 浏览:987
电脑下载的歌可以拉到文件夹吗 浏览:722
千锋3g学院android 浏览:445
linux中的yum命令 浏览:239
压缩面膜有几种 浏览:575
怎么更改安卓程序级别 浏览:393
安卓系统运行慢怎么办呢 浏览:808
外地人在买车本地可以解压嘛 浏览:907
相册软件加密怎么取消 浏览:251
麦克风app怎么打开 浏览:22
java泛型t和 浏览:356
计算机英文pdf 浏览:587
单片机控制的直流调速系统 浏览:130
抖音上解压视频书单号怎么做 浏览:165
软件加密之后忘了密码怎么办 浏览:944
文件夹怎么弹出来的 浏览:209
51单片机引脚图电路 浏览:214
麦当劳员工怎么登录app 浏览:530
目前什么系统编程语言最好 浏览:488
破晓传说未加密 浏览:450