Thank you for useful script! It fixed chattering problem with my Rapoo E9260 keyboard and works better than other solutions suggested elsewhere.
Unfortunately since I run it on notebook with docking station, I frequently undock my notebook and then problem starts. In most cases (not every time), soon after the dock and keyboard is disconnected, the python3 process starts consuming full CPU thread capacity, leading to ventilator running in full speed until the process is terminated. It happens both in case running script from service or command line.
I hope you can fix this issue.