⑴ 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 shell 如何获取按键值
"${a}" = "^[OP"
^[OP 是先按 Ctrl +v 在按F1 得到的
http://bbs.chinaunix.net/thread-1475196-1-1.html
⑶ 在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上怎么在C中获取方向键键值
特殊的键,如方向键,功能键等,可以使用读取普通键的方式,但是要连读两次。
⑸ 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 c中得到按键的键盘扫描码
键盘扫描码有两种:
一个是make code,也就是键被按下和按住不放时产生
另一种是break code,在键被释放时产生。
每个键都有自己唯一的make code和break code。
提供一个我在Linux下的实现,就是使用ioctl 改变终端I/O模式。
测试程序在“a”健被按下时退出。
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/kd.h>
int main(void)
{
struct termios oldtermios,newtermios;
int oldmode;
unsigned short key;
int i;
if((tcgetattr(fileno(stdin),&oldtermios))<0)
{
perror("tcgetaddr error");
exit(1);
}
if((tcgetattr(fileno(stdin),&newtermios))<0)
{
perror("tcgetaddr error");
exit(1);
}
newtermios.c_lflag &= ~(ICANON|ECHO|ISIG);
newtermios.c_iflag = 0;
newtermios.c_cc[VMIN] = 0;
newtermios.c_cc[VTIME] = 1; //=0延时0 ,=1延时1s
if(tcsetattr(fileno(stdin),TCSAFLUSH,&newtermios))
{
perror("tcsetattr error");
exit(1);
}
ioctl(fileno(stdin),KDGKBMODE,&oldmode);
if(ioctl(fileno(stdin),KDSKBMODE,K_RAW))
{
perror("ioctl error");
exit(1);
}
while(1)
{
if(read(fileno(stdin),&key,sizeof(key))>0)
printf(" key = 0x%x \n",key);
if (key == 0x1e)//key a down , exit.
break;
key = 0;
}
ioctl(fileno(stdin),KDSKBMODE,oldmode);
tcsetattr(fileno(stdin),TCSANOW,&oldtermios);
return 0;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ma100/archive/2007/02/07/1504270.aspx
以上代码,我在suse liux下,没有成功。原因是 if(ioctl(fileno(stdin),KDSKBMODE,K_RAW)) 没有成功。
参考下面文章:http://www.linuxjournal.com/article/2783,需要弄清楚ioctl对键盘的操作。
⑺ 如何在linux下接收串口2发来的按键数据
用echo可以,不过需要一个串口的软件,就跟win的超级终端一样,开启后连接串口,然后另一边发送数据,你这边就能显示出来,我记得好像叫做minicom
⑻ 如何读取ARM开发板按键信息(在linux操作系统环境下,按键已经有驱动,并且做成了/dev/buttons设备)
这个得看驱动工程师咋设计的,中断的方式应该设成双边沿触发,也就是在按下和抬起多时候都会产生中断,那么两次中断才算是一次完整的按键,或者是按键抬起的时候产生中断,就在抬起的时候才会去响应,不用考虑 两次的问题
⑼ 如何读取ARM开发板按键信息(在linux操作系统环境下,按键已经有驱动,并且做成了/dev/buttons设备)
用定时器处理程序,查询按键是否被按下,如果是按下的,把状态记录到缓冲区,然后开启定时器延时去抖,设定一个时间,如果发现没有被按下,就认为抬起,开启相应中断,函数key_timer_handler