-1

In a project of mine I am trying to change the speed of the mouse as a requirement is hit. For this to work I either have to change the dpi of the mouse through python, or make python click the little dpi button on the mouse.

I believe the latter is easier but I am open to suggestions. My main problem is if the button has a nice and if the “dpi button” is accessible by importing the Python mouse library. The first solution could also work although I may need help since I do not know much OS.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

This is Autoit which only works on Windows!

#Include <WinAPI.au3>

Global Const $SPI_SETMOUSESPEED = 113
Global Const $SPIF_SENDCHANGE = 2

Global Const $Speed = 2 ; 0...20, 10 - Default

_WinAPI_SystemParametersInfo($SPI_SETMOUSESPEED, 0, $Speed, $SPIF_SENDCHANGE)

This is Python code

import ctypes

try:
    import tkinter as tk
except ImportError:
    import Tkinter as tk


def change_speed(speed=10):
    #   1 - slow
    #   10 - standard
    #   20 - fast
    set_mouse_speed = 113   # 0x0071 for SPI_SETMOUSESPEED
    ctypes.windll.user32.SystemParametersInfoA(set_mouse_speed, 0, speed, 0)


def proper_close():
    change_speed()
    root.destroy()

root = tk.Tk()
root.protocol('WM_DELETE_WINDOW', proper_close)
tk.Button(root, text='Slow', command=lambda: change_speed(1)).pack(expand=True, fill='x')
tk.Button(root, text='Standard', command=change_speed).pack(expand=True, fill='x')
tk.Button(root, text='Fast', command=lambda: change_speed(20)).pack(expand=True, fill='x')
root.mainloop()
Xenobiologist
  • 2,091
  • 1
  • 12
  • 16