Multiple Fixes & New Mouse Filtering Feature#21
Open
some1ataplace wants to merge 80 commits into
Open
Conversation
Reference for blacklist or command line arguments
Core logic. Updated with the double-letter fix and specific key filtering.
Entry point. Updated with CPU fix, config routing, and CLI parsing.
This is the mouse version of the filter. It instantly forwards movement data so your cursor remains flawlessly smooth, and only applies the chatter filter to button clicks (like BTN_LEFT, BTN_RIGHT, etc.).
Mouse devices end in -event-mouse. This file searches specifically for mice.
This is the entry point for the mouse fix. You run this instead of python3 -m src. Read from the new mouse_config.py, exactly how we did for the keyboard.
This file holds the configuration for the mouse and lists all the possible button values you can pass to it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There are multiple changes applied in this PR. Would appreciate some testing from others in case anything was missed.
Description of Changes
This PR is a major overhaul that resolves several long-standing open issues, drastically improves system stability, and introduces a massive expansion of features—most notably, Mouse double-click and Scroll-wheel filtering.
(Note for the maintainer: Because this now handles both keyboards and mice, you might want to consider renaming the repository to
HardwareChatteringFix-Linuxor something similar to improve SEO for people searching for Linux mouse double-click fixes!)Massive Feature Expansion (New)
keyboard_mainandmouse_main. The mouse logic natively bypasses X/Y cursor movement and scrolling (EV_REL/EV_ABS) so the cursor remains flawlessly smooth, applying the chatter filter only to physical button clicks.-sr(Reverse) and-sd(Double-Action) thresholds to explicitly block faulty hardware encoders that jump in the wrong direction or fire twice for a single physical notch.-jl(Jump Limit) to drop massive, impossible cursor jumps caused by dirty laser sensors (e.g., jumping >300px in a single frame).50mswhile leaving your gaming WASD keys at a crisp15ms).-rflag that enables a native polling loop. This allows wireless/Bluetooth mice to safely reconnect on the fly for non-systemd users!Core Bug Fixes
os.path.exists(). If the device vanishes, it performs a cleansys.exit(0). Systemd'sRestart=alwaysparameter then safely polls every 5 seconds until the device is reconnected, consuming ~0% CPU._last_key_code, the threshold is safely bypassed if the previous key pressed was a different character. (This logic is also applied to alternating mouse clicks).--keys KEY_A) or the new config files. If empty, it defaults to filtering everything.event.value > 1) are explicitly forwarded without filtering, ensuring held shortcuts behave identically to a physical keyboard.READMEreminding modern Linux users how to install the dependency using avenvor--break-system-packages.Testing Guide for Reviewers
Since it can be difficult to physically force a healthy keyboard or mouse to "chatter" on command, the best way to test this script is to artificially raise the threshold to a massive number (like
1000 ms/ 1 second).Phase 1: Preparation & Setup
Ensure your project folder matches the new structure:
Pre-Flight Check
Before running any manual tests, you must stop any background services that might be holding the exclusive lock on your hardware, otherwise you will get
[Errno 16] Device or resource busy:sudo systemctl stop keyboard_chattering.service sudo systemctl stop mouse_chattering.service # OR, if using the fallback method: sudo pkill -f keyboard_main sudo pkill -f mouse_mainPhase 2: Testing Keyboard Core Fixes (Typing Tests)
Run this command in the terminal (sets threshold to 1 second,
-v 2turns on DEBUG logging):Akey twice rapidly. Only oneashould type on your screen. You should seeFILTEREDin the terminal.a, thenb, thenaas fast as you can. You should seeabatyped on your screen. Thebsuccessfully resets the filter fora.Shift, then pressa. It should successfully produce a capitalA. Held events bypass the filter natively. (PressCtrl+Cto stop).Phase 3: Testing Mouse Core Fixes
Run this command for the mouse module:
Ctrl+Cto stop).Phase 4: Testing Advanced Thresholds & Targeting
Let's test CLI targeting and the Per-Key/Per-Button config thresholds.
Keyboard Targeting:
Atwice rapidly. Then pressBtwice rapidly.Awill only type once (filtered). ButBwill type twice (bb) because it is safely bypassing the filter!Per-Key Thresholds (Keyboard Config):
src/keyboard_config.pyand setKEY_THRESHOLDS = {"KEY_A": 1000}.sudo python3 -m src.keyboard_main -t 0 -v 2(Default is 0ms, so everything bypasses EXCEPT 'A').Srapidly, it spams instantly. TypeArapidly, it is restricted to once per second.Per-Button Thresholds (Mouse Config):
src/mouse_config.pyand setBUTTON_THRESHOLDS = {"BTN_RIGHT": 1000}.sudo python3 -m src.mouse_main -t 0 -v 2Phase 5: Testing Remapping
Keyboard Remapping:
src/keyboard_config.pyand setKEY_MAP = {"KEY_A": "KEY_B"}.sudo python3 -m src.keyboard_main -v 2A, your computer will typeb. Check the terminal forREMAPPED to KEY_B.Mouse Remapping:
src/mouse_config.pyand setBUTTON_MAP = {"BTN_SIDE": "BTN_MIDDLE"}.sudo python3 -m src.mouse_main -v 2(Note: Remember to clear your config maps after testing!)
Phase 6: Testing Scroll Wheel Advanced Features
Scroll Reverse Glitch:
BLOCKED REVERSE SCROLL.Scroll Double-Action:
BLOCKED DOUBLE-SCROLLin the terminal. (CAUTION: Do not use-sdon infinite/free-spin scroll wheels!)Scroll Axis Allowlist:
src/mouse_config.pyand setFILTERED_SCROLL_AXES = {"REL_WHEEL", "REL_WHEEL_HI_RES"}(Targeting vertical only).sudo python3 -m src.mouse_main -sr 5000 -v 2Phase 7: Testing Sensor Anomalies
It is impossible to force a hardware glitch on command, but we can set the limits so low that normal movements trigger the block, proving the code works.
BLOCKED TELEPORT. Your cursor will stutter. (In actual use, you'd set this to something like-jl 500to only block true hardware glitches).Phase 8: Testing Hardware Disconnect & Reconnection
Clean Exit (Systemd Mode):
Run either script normally (without the
-rflag):Keyboard disconnected... Exiting cleanly.The script closes safely instead of crashing or maxing out your CPU.Auto-Reconnect (Hotplug Mode):
Run the script WITH the
-rflag:Waiting for mouse...every 2 seconds. Plug it back in. Within 2 seconds, the terminal printsSuccessfully connected...and the mouse works again instantly without needing to restart the script.