看一下
input_dev
結構體,
只列出了和我們討論的內用有關的成員:
struct input_dev
接下來我們看一下input_register_device
函式,只關心我們討論的部分:
int input_register_device(struct input_dev *dev)
...... }
我麼看到該函式初始化了乙個核心定時器。input_repeat_key
則為按鍵重複的關鍵函式,原始碼如下:
static void input_repeat_key(unsigned long data)
if (dev->rep[rep_period])
mod_timer(&dev->timer, jiffies +
msecs_to_jiffies(dev->rep[rep_period]));
}
spin_unlock_irqrestore(&dev->event_lock, flags); }
但是我們沒有看到add_timer
函式,核心定時器是在什麼時候加入核心定時器鍊錶的呢
?我們知道在有按鍵按下是要使用
input_report_key
函式報告的,看一下該函式:
static inline void input_report_key(struct input_dev *dev, unsigned int code, int value)
繼續往下看:
void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
在該函式中我們主要看input_handle_event
函式:
static void input_handle_event(struct input_dev *dev,
unsigned int type, unsigned int code, int value)
disposition = input_pass_to_handlers;
} break;
......
case ev_rep:
if (code <= rep_max && value >= 0 && dev->rep[code] != value)
break;
......
if (disposition != input_ignore_event && type != ev_syn)
dev->sync = 0;
if ((disposition & input_pass_to_device) && dev->event)
dev->event(dev, type, code, value);
if (disposition & input_pass_to_handlers)
input_pass_event(dev, type, code, value); }
我們主要看input_start_autorepeat
函式:
static void input_start_autorepeat(struct input_dev *dev, int code)
}我們還是沒看到add_timer
函式,其實不需要
add_timer
函式也是可以啟動核心定時器的,那就是
mod_timer
函式,該函式的執行過程等於
del_timer(timer); timer->expires = expires; add_timer(timer);
所以就會啟動核心定時器。
input_report_key的原型如下:
static inline void input_report_key(struct input_dev *dev, unsigned int code, int value);
我們知道在使用input_report_key
函式時引數
value
表示的是按鍵的按下還是沒按下。
0表示按鍵釋放,非
0表示按鍵按下。我們看到當按鍵按下時,如果配置了按鍵是可以重複的,就會執行
input_start_autorepeat
函式,該函式就會啟動核心定時器,接著就會執行
input_repeat_key
函式,在該函式中執行:
input_pass_event(dev, ev_key, dev->repeat_key, 2);
其中dev->repeat_key
儲存的為按下按鍵時的值,我們看到
value
引數的值為
2,在看
input_handle_event
,該函式中
if (value != 2)
裡面的語句就不能執行,也就不會執行
__change_bit(code, dev->key);
所以可以一直執行
input_repeat_key中的
if (test_bit(dev->repeat_key, dev->key) &&
is_event_supported(dev->repeat_key, dev->keybit, key_max))
裡面的語句。執行:
mod_timer(&dev->timer, jiffies +msecs_to_jiffies(dev->rep[rep_period]));
重啟定時器,如此定時器就一直執行下去。
但我們釋放按鍵時。就會改變dev->key
的值,使
input_repeat_key中的
if (test_bit(dev->repeat_key, dev->key) &&
is_event_supported(dev->repeat_key, dev->keybit, key_max))
語句中的內容不能執行了,所以核心定時器也就停止了工作,既停止了按鍵的重複。
python中如何用input 同時輸入多個資料
a,b,c input 輸入a,b空格隔開 split print type a print type b print type c 這種方式輸入的字元格式為字串型別 輸入a,b,c空格隔開 1 2 3 或者可以用 隔開 a,b,c input 輸入a,b,c用,隔開 split print typ...
input輸入子系統 大致流程
1 分配乙個裝置結構體 input dev input allocate device input allocate device 函式在記憶體中為輸入裝置結構體分配乙個空間,並對其主要的成員進行了初始化 2 定義裝置所支援的動作和鍵值 set bit ev syn,input dev evbit ...
核心輸入子系統input解析
android x windows qt等眾多應用對於linux系統中鍵盤 滑鼠 觸控螢幕等輸入裝置的支援都通過 或越來越傾向於標準的input輸入子系統。因為input子系統已經完成了字元驅動的檔案操作介面,所以編寫驅動的核心工作是完成input系統留出的介面,工作量不大。但如果你想更靈活的應用它...