原项目为screenkey,在 tag v1.5 的基础上添加计数功能
├── Screenkey
│ ├── __init__.py
│ ├── inputlistener.py 运行后可以在终端输出 按键的编码
│ ├── keysyms.py 编码对应的按键
│ ├── labelmanager.py
│ ├── screenkey.py 主程序,运行后可以显示按下的按键、鼠标点击和滚动
│ └── xlib.py 通过 x11 获取输入
├── setup.cfg
├── setup.py
├── kmdata.json : static data
└── kmcounter.py : main code
- install screenkey(v1.5+) or clone screenkey source code
- if install screenkey, just get kmcounter.py; If clone screenkey source code, get kmcounter.py and put it into screenkey like file tree above.
- set kmcounter.py autostart. static data will be stored in kmdata.json.
发现统计数据里z分大小写统计了,于是在合并前再加一步合并大小写字母的统计频数,然后统计一下平均数
('d', 187930) <class 'tuple'> ('XF86Launch4', 1) <class 'dict'>
总按键次数: 1216018
按键总数: 124
平均数: 9806.59677419355
发现不对劲啊,按键数量多了些吧,人工数键盘一共 80 个按键(16+14+14+13+12+11),也就是平均每个按键按下了 15200 次,从上个月开始(11.5~12.24),一共 50 天,平均一天 304 下,当然这只是其中一台设备的统计数据,期间我还在另一台设备上进行了统计。
为什么统计的按键比实体按键多?因为键盘有 Fn,就多出了 16 个,触摸板多两个按键
默认布局按键底色为 #cccccc,我将按下次数最少的颜色定义为 #00ffff,次数最多的颜色定义为 #ff0000,那么以按键次数为自变量、颜色为因变量的一次方程为
f(x) = 0x00ffff + (x-min) * ((0xff0000-0x00ffff) / (max-min))
= 65535 + (x-min) * ((16711680-65535) / (max-min))
= 65535 + (x-min) * ((16646145) / (max-min))
Python max()方法扩展:求字典中值最大的键 千鱼千寻 2020-09-14
因查阅日志发现本程序的输出占了太大篇幅,因此只留出程序的错误输出。autostart 路径:sh -c "sleep 3 && cd /home/mifen/Documents/code/kmcounter/ && nohup python kmcounter.py >/dev/null 2>log & "
refactor 将代码移动到上层目录,解决未安装 screenkey 时无法允许代码的bug
autostart 路径因此有所变化:sh -c "sleep 3 && cd /home/mifen/Documents/code/kmcounter/ && nohup python kmcounter.py >/dev/null 2>log & "
feature 监听键盘按键按下事件+鼠标按键按下事件
feature 按键次数数据存储到文件
refactor 数据的读取和保存
question glib.main_context_default().iteration()
不理解作用,尝试去掉则程序无法正常运行
字母、数字、方向运算符、TAB可以长摁也会累加次数,鼠标按键、shift、ctrl、alt、super 则不会
开启启动 参阅Autostarting. 我使用的 XFCE DE, 在设置-启动中添加命令即可,如 sh -c "sleep 3 && cd /home/mifen/Documents/code/screenkey/kmcounter/ && python kmcounter.py"
,而不是 python /home/mifen/Documents/code/screenkey/kmcounter/kmcounter.py
,后者会存在路径问题无法识别到 kmdata.json 的问题,cd /home/mifen/Documents/code/screenkey/kmcounter/ && python kmcounter.py
测试发现没法启动
fix 文件不存在不会自动创建的bug
fix 程序在关机时不会自动保存数据的bug
refactor 封装成类,这样接收信号退出的时候就不需要额外传参了
https://github.com/ijprest/keyboard-layout-editor
Commit message 和 Change log 编写指南 阮一峰 2016年1月 6日
shutdown 是指向 systemctl 的动态链接,systemctl 是可执行文件,可是直接执行 shutdown 会一分钟后关机,执行 systemctl 则不会唉
python脚本如何监听终止进程行为,如何通过脚本名获取pid 铁柱同学 于 2019-10-30 :signal
shutdown - Unix, Linux Command:shutdown 会发送 SIGTERM 信号
shutdown brings the system down in a secure way. All logged-in users are notified that the system is going down, and login(1) is blocked. It is possible to shut the system down immediately or after a specified delay. All processes are first notified that the system is going down by the signal SIGTERM.
what-signal-is-sent-to-running-programs-scripts-on-shutdown
While on shutdown the running processes are first told to stop by init(from sendsigs on old implementations, according to @JdeBP)/systemd.
The remaining processes, if any, are sent a SIGTERM. The ones that ignore SIGTERM or do not finish on time, are shortly thereafter sent a SIGKILL by init/systemd.
SIGTERM: Linux Graceful Termination | Exit Code 143, Signal 15 Daniel Slavin October 16th, 2022
kill command sends a SIGTERM signal
command to send SIGKILL: kill -9 [ID]
How to terminate running Python threads using signals November 24, 2016 George Notaras
nohup不输出nohup.out日志信息,已解决。勤奋能干二师弟 2019-06-04
只输出错误信息到日志文件
nohup java -jar yourProject.jar >/dev/null 2>log &
什么信息也不要
nohup java -jar yourProject.jar >/dev/null 2>&1 &
screenkey:在屏幕上显示当前按键。keysms.py 中有 function
这一行,但是我按下的时候并没有显示出来。super\alt\shift,在偏好设置里打开显示shift,然后显示Mouse才可以看到shift、alt、ctrl。从xlib.py中可以看出来是通过x11的库读取的输入。
AlynxZhou/showmethekey: screenkey 替代方案, 适配 X11 和 Wayland.通过 libinput 获取用户输入。需要root权限,使用上不如screenkey开箱即用,也没心思继续搞懂怎么用。
KMCounter:ahk 开源 windows 脚本。功能和界面优秀,commit message 写的一塌糊涂。推出程序时 SaveData 通过 IniWrite 将数据存储到文件(KMCounter.ini)中
whatpulse:闭源,支持三大os。除了记录键盘、还会记录网络传输,隐私协议中收集匿名数据,统计界面看起来更炫酷
Mousotron : Mouse and keyboard activity monitor:Windows 7/8/10,闭源 5$,界面看起来很上古