Note
Read the blog "Decoding your Daily Typing Habits: A Simple Tutorial on Keyboard Monitoring" for a full explanation.
Other dependencies can be installed by:
pip3 install -r requirements.txt
- Obtain a free Greptime service from GreptimeCloud.
- Go to the "Connect" tab and find the connection string.
- Copy
.env.example
to.env
and set the connection string.
Run the agent script to listen to keyboard inputs:
python3 agent.py
You should see logs like:
2024-03-07 20:57:53,799 INFO listener_thread Listening...
2024-03-07 20:58:01,510 INFO sender_thread sent: Key.backspace
2024-03-07 20:58:01,947 INFO sender_thread sent: Key.enter
2024-03-07 20:58:02,498 INFO sender_thread sent: Key.shift+'#'
2024-03-07 20:58:02,938 INFO sender_thread sent: Key.space
2024-03-07 20:58:03,377 INFO sender_thread sent: Key.cmd+Key.right
2024-03-07 20:58:04,052 INFO sender_thread sent: Key.cmd+'s'
...
The following sample queries are executed from the Web Dashboard.
SELECT hits, COUNT(*) as times
FROM keyboard_monitor
WHERE hits NOT LIKE '%+%'
GROUP BY hits
ORDER BY times DESC limit 10;
SELECT hits, COUNT(*) as times
FROM keyboard_monitor
WHERE hits LIKE '%+%'
GROUP BY hits
ORDER BY times DESC limit 10;
Read more about GreptimeDB's powerful RANGE QUERY.
SELECT
ts,
COUNT(1) RANGE '1h' as times
FROM keyboard_monitor ALIGN '1h'
ORDER BY ts DESC
LIMIT 10;
It's easy to use Streamlit to display the input frequency.
Run the following script:
streamlit run display.py
It'll open a window in your browser and shows the data frames:
If the window is not opened, you can explicit view it via http://localhost:8501.