导航:首页 > 操作系统 > 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获取键盘相关的资料

热点内容
程序员能力关键词 浏览:615
plc编程高级视频教程 浏览:610
java递归求n 浏览:84
python绝对路径导入 浏览:126
nex5g加密 浏览:975
18的空岛服务器地址 浏览:86
程序员要学什么硬件 浏览:666
股票涨跌源码怎么看 浏览:576
加密软件做法 浏览:55
美国程序员有多少中国人 浏览:739
人民日报app里怎么看新闻早班车 浏览:585
忘了app怎么办 浏览:529
如何用云服务器做云平台 浏览:299
非箍筋加密区剪力 浏览:119
利联科技服务器卡怎么办 浏览:385
js和python哪个好 浏览:463
c盘的哪些文件夹没用 浏览:83
文件为什么会超出在线解压限制 浏览:591
python类实例化对象 浏览:797
硬盘dos外部命令 浏览:794