Linux上使用Python統計每天的鍵盤輸入

kuangcp發表於2019-04-16

Github 專案主頁工具原始碼

分析結果:

total : 15981
1568.0 == Backspace
1103.0 == Tab
1038.0 == Enter
900.0 == Space
765.0 == L_Alt
730.0 == L_Control
700.0 == S
689.0 == L_Shift
544.0 == I
500.0 == A
494.0 == E
410.0 == N

最後的統計結果,: 刪除,Enter 空格 使用最多

Web Redis 此專案將redis中的資料使用 echarts 做了視覺化

這裡寫圖片描述

Python的evdev模組

官方文件

此專案基於該模組實現的

# 簡易Demo: 實現對鍵盤敲擊次數的計數
from evdev import InputDevice
from select import select

def detectInputKey(count):
    dev = InputDevice('/dev/input/event0')
    while True:
        select([dev], [], [])
        for event in dev.read():
            if event.value == 1 and event.code != 0:
                count+=1
                print(count)

detectInputKey(0)
複製程式碼

注意要root許可權執行.

其他可選擇的基礎工具

1. evtest

evtest 使用: evtest "/dev/input/eventX" X 為對應的數字

2. input-utils

debian列表 暫時還不會用...


如果是安卓就更方便 getevent和setevent getevent/sendevent 使用說明

相關文章