⑴ 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