DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: mouse speed switcher  (Read 13,500 times)

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • Plugin Coding Medal
    • Participated in NANY Challenge Once
mouse speed switcher
« on: April 04, 2008, 09:01 AM »
Hi,
what I really would like to have is a tiny program which would stay in tray and after clicking on it, it would change speed of mouse (so that I can switch between usb mouse and touchpad). Two predefined speeds of mouse would be fine. Also ability to assign some key to it would be great. Is that possible with autohotkey? If so, just tell me pls the function which changes mouse speed and I will code it by myself. There exists already mouseswitcher, but it is paid.
Thanks for any ideas ;)
My open-source online piano game: https://github.com/musicope/game

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • Plugin Coding Medal
    • Participated in NANY Challenge Once
Re: mouse speed switcher
« Reply #1 on: April 04, 2008, 09:07 AM »
I have found:
http://www.autohotkey.com/forum/viewtopic.php?t=5605
So I will play a little with it and see :up:
My open-source online piano game: https://github.com/musicope/game

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,931
    • Gathering Badge
    • Plugin Coding Medal
    • Participated in NANY Challenge Seventeen Times
    • Cody Award
    • Coding Snacks
    • Volunteers/Staff
Re: mouse speed switcher
« Reply #2 on: April 04, 2008, 10:23 AM »
nice idea.  :up:

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • Plugin Coding Medal
    • Participated in NANY Challenge Once
Re: mouse speed switcher
« Reply #3 on: April 04, 2008, 11:05 AM »
I have found following:
Code: (autoit)
/*
AutoHotkey Version: 1.x
Language:   English
Platform:   WinXP

Title:      Laptop Mouse Monitor
Author:      Wesley Treat, www.wesleytreat.com
Date:      May 2006

Script Function:
If a USB mouse is plugged into the laptop, optimize the pointer speed and
precision settings for the mouse. If it's not, optimize the settings
for the touch pad. Monitor for changes in mouse's presence.
*/


; ============================================================
; CONFIGURATION
; ============================================================

; ------------------------------------------------------------
; USER POINTER SETTINGS

; Mouse ID
; Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Mouclass\Enum
; to determine the ID of your mouse. This should be the value of the key that
; appears and disappears when you plug in and unplug your mouse. You can
; probably just use "HID."

MouseID = HID


; Pointer Speed (1-20)
PadSpeed = 10
MouseSpeed = 12

; Enhance Pointer Precision
PadEnhance = 1
MouseEnhance = 0

; Precision Thresholds
PadThreshold1 = 6
PadThreshold2 = 10
MouseThreshold1 = 0
MouseThreshold2 = 0

; For details on precision and threshold settings, see
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefSystemParametersInfo.asp
; under SPI_SETMOUSE. By default, thresholds 1 and 2 are "6" and "10" respectively.


; Use a tray icon?
TrayIcon = 1

; Tray Icons
; If you want the tray icon to reflect the current settings, enter a valid
; PadIcon and PadIconGroup. To use the only standard AutoHotkey icon, comment
; out all the icon locations.

MouseIcon = %A_WinDir%\system32\main.cpl
MouseIconGroup = 1

; The likely location of the Alps Touch Pad icon.
; PadIcon = %ProgramFiles%\Apoint\Apoint.exe
; PadIconGroup = 1

; The likely location of the Synaptics Touch Pad icon.
; PadIcon = %ProgramFiles%\Synaptics\SynTP\SynTPEnh.exe
; PadIconGroup = 1


; If you like, you can change the names for your devices. These names are
; reflected in the tooltips.
MouseName = Mouse
PadName = Touch Pad

; ------------------------------------------------------------
; SCRIPT SETTINGS - YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE.

If !TrayIcon
   Menu, Tray, NoIcon

; Constants
; Read more at the following:
; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
; http://www.pinvoke.net/search.aspx?search=SPI&namespace=%5BAll%5D
SPI_GETMOUSE =      0x0003
SPI_SETMOUSE =      0x0004
SPI_GETMOUSESPEED =   0x0070
SPI_SETMOUSESPEED =   0x0071

; Watch for hardware changes
OnMessage(0x219, "HardwareUpdate")

; Check whether or not the mouse exists to begin with and make sure the pointer
; settings match.
   Gosub, MouseCheck
   Gosub, ChangeSettings
   If !MousePresent and !FileExist(PadIcon) and FileExist(MouseIcon)
      Menu, Tray, Icon, %MouseIcon%, %MouseIconGroup%
   MouseLast = %MousePresent%
   ToolTip, Pointer Settings Set To: %CurrentName%
   Sleep, 2000
   ToolTip
   Return


Exit ; Everything above this line is run when the script is loaded.


; ============================================================
; FUNCTIONS & SUBROUTINES
; ============================================================

HardwareUpdate()
{
   Global MouseLast
   Global MousePresent
   Global CurrentName
   Gosub, MouseCheck
   ; We might get phantom hardware-change messages, so make sure the status
   ; of the mouse has actually changed before changing any settings.
   If MousePresent = %MouseLast%
      Exit
   Else
   {
      Gosub, ChangeSettings
      MouseLast = %MousePresent%   ; Update mouse status.
      ToolTip, Pointer Settings Changed To: %CurrentName%
      Sleep, 2000
      ToolTip
   }
   Return
}

MouseCheck:
   MousePresent = 0
   Sleep, 1000   ; Give the registry a moment to update.
   Loop, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Services\Mouclass\Enum, 0, 0
   {
      RegRead, CurrentValue
      IfInString, CurrentValue, %MouseID%
      {
         MousePresent = 1
         Break   ; Don't check any more values.
      }
   }
   Return

ChangeSettings:
   If MousePresent
   {
      CurrentName = %MouseName%
      DeviceSpeed = %MouseSpeed%
      DeviceEnhance = %MouseEnhance%
      DeviceThreshold1 = %MouseThreshold1%
      DeviceThreshold2 = %MouseThreshold2%
      If TrayIcon and FileExist(MouseIcon)
         Menu, Tray, Icon, %MouseIcon%, %MouseIconGroup%
      Menu, Tray, Tip, Current Pointer Settings: %CurrentName%
   }
   Else
   {
      CurrentName = %PadName%
      DeviceSpeed = %PadSpeed%
      DeviceEnhance = %PadEnhance%
      DeviceThreshold1 = %PadThreshold1%
      DeviceThreshold2 = %PadThreshold2%
      If TrayIcon and FileExist(PadIcon)
         Menu, Tray, Icon, %PadIcon%, %PadIconGroup%
      Menu, Tray, Tip, Current Pointer Settings: %CurrentName%
   }

   VarSetCapacity(DeviceArray, 12, 0)
   InsertInteger(DeviceThreshold1, DeviceArray, 0)   ; Reg. Value MouseThreshold1
   InsertInteger(DeviceThreshold2, DeviceArray, 4)   ; Reg. Value MouseThreshold2
   InsertInteger(DeviceEnhance, DeviceArray, 8)      ; Reg. Value MouseSpeed

   InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
   ; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
   ; only pSize number of bytes starting at pOffset are altered in it.
   {
      Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
         DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
   }

   ; Keep this here for future reference.
   ; DllCall("SystemParametersInfo", UInt, SPI_GETMOUSESPEED, UInt, 0, UIntP, SpeedCurrent, UInt, 0)

   ; Change the pointer speed.
   DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt, 0, UInt, DeviceSpeed, UInt, 1)
   ; Change the pointer precision settings.
   DllCall("SystemParametersInfo", UInt, SPI_SETMOUSE, UInt, 0, Str, DeviceArray, UInt, 1)
   Return
It changes mouse/touchpad setting according to if USB mouse is present or not. It would be even better if anyone could add option to switch mouse/touchpad manualy through program menu. Unfortunately I do not know autohotkey to do it by myself.
My open-source online piano game: https://github.com/musicope/game

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,277
    • Coding Snacks
    • Volunteers/Staff
    • Gathering Badge
    • Participated in NANY Challenge Once
    • Linux User
Re: mouse speed switcher
« Reply #4 on: April 04, 2008, 12:45 PM »
czechboy, would this script (or the original one) be helpful with this problem i'm having here?

Original address: https://www.donationcoder.com/forum/index.php?topic=12935.0