Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 04, 2016, 12:26:56 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: mouse speed switcher  (Read 7186 times)

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
mouse speed switcher
« on: April 04, 2008, 04:01:30 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
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: mouse speed switcher
« Reply #1 on: April 04, 2008, 04:07:45 AM »
I have found:
http://www.autohotke...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: 36,406
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: mouse speed switcher
« Reply #2 on: April 04, 2008, 05:23:10 AM »
nice idea.  :up:

czb

  • Honorary Member
  • Joined in 2007
  • **
  • Posts: 336
    • View Profile
    • My open-source online piano game
    • Donate to Member
Re: mouse speed switcher
« Reply #3 on: April 04, 2008, 06:05:24 AM »
I have found following:
Code: AutoIt [Select]
  1. /*
  2. AutoHotkey Version: 1.x
  3. Language:   English
  4. Platform:   WinXP
  5.  
  6. Title:      Laptop Mouse Monitor
  7. Author:      Wesley Treat, www.wesleytreat.com
  8. Date:      May 2006
  9.  
  10. Script Function:
  11. If a USB mouse is plugged into the laptop, optimize the pointer speed and
  12. precision settings for the mouse. If it's not, optimize the settings
  13. for the touch pad. Monitor for changes in mouse's presence.
  14. */
  15.  
  16.  
  17. ; ============================================================
  18. ; CONFIGURATION
  19. ; ============================================================
  20.  
  21. ; ------------------------------------------------------------
  22. ; USER POINTER SETTINGS
  23.  
  24. ; Mouse ID
  25. ; Check HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Mouclass\Enum
  26. ; to determine the ID of your mouse. This should be the value of the key that
  27. ; appears and disappears when you plug in and unplug your mouse. You can
  28. ; probably just use "HID."
  29.  
  30. MouseID = HID
  31.  
  32.  
  33. ; Pointer Speed (1-20)
  34. PadSpeed = 10
  35. MouseSpeed = 12
  36.  
  37. ; Enhance Pointer Precision
  38. PadEnhance = 1
  39. MouseEnhance = 0
  40.  
  41. ; Precision Thresholds
  42. PadThreshold1 = 6
  43. PadThreshold2 = 10
  44. MouseThreshold1 = 0
  45. MouseThreshold2 = 0
  46.  
  47. ; For details on precision and threshold settings, see
  48. ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/html/cerefSystemParametersInfo.asp
  49. ; under SPI_SETMOUSE. By default, thresholds 1 and 2 are "6" and "10" respectively.
  50.  
  51.  
  52. ; Use a tray icon?
  53. TrayIcon = 1
  54.  
  55. ; Tray Icons
  56. ; If you want the tray icon to reflect the current settings, enter a valid
  57. ; PadIcon and PadIconGroup. To use the only standard AutoHotkey icon, comment
  58. ; out all the icon locations.
  59.  
  60. MouseIcon = %A_WinDir%\system32\main.cpl
  61. MouseIconGroup = 1
  62.  
  63. ; The likely location of the Alps Touch Pad icon.
  64. ; PadIcon = %ProgramFiles%\Apoint\Apoint.exe
  65. ; PadIconGroup = 1
  66.  
  67. ; The likely location of the Synaptics Touch Pad icon.
  68. ; PadIcon = %ProgramFiles%\Synaptics\SynTP\SynTPEnh.exe
  69. ; PadIconGroup = 1
  70.  
  71.  
  72. ; If you like, you can change the names for your devices. These names are
  73. ; reflected in the tooltips.
  74. MouseName = Mouse
  75. PadName = Touch Pad
  76.  
  77. ; ------------------------------------------------------------
  78. ; SCRIPT SETTINGS - YOU SHOULDN'T NEED TO CHANGE ANYTHING BELOW THIS LINE.
  79.  
  80. If !TrayIcon
  81.    Menu, Tray, NoIcon
  82.  
  83. ; Constants
  84. ; Read more at the following:
  85. ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/systemparametersinfo.asp
  86. ; http://www.pinvoke.net/search.aspx?search=SPI&namespace=%5BAll%5D
  87. SPI_GETMOUSE =      0x0003
  88. SPI_SETMOUSE =      0x0004
  89. SPI_GETMOUSESPEED =   0x0070
  90. SPI_SETMOUSESPEED =   0x0071
  91.  
  92. ; Watch for hardware changes
  93. OnMessage(0x219, "HardwareUpdate")
  94.  
  95. ; Check whether or not the mouse exists to begin with and make sure the pointer
  96. ; settings match.
  97.    Gosub, MouseCheck
  98.    Gosub, ChangeSettings
  99.    If !MousePresent and !FileExist(PadIcon) and FileExist(MouseIcon)
  100.       Menu, Tray, Icon, %MouseIcon%, %MouseIconGroup%
  101.    MouseLast = %MousePresent%
  102.    ToolTip, Pointer Settings Set To: %CurrentName%
  103.    Sleep, 2000
  104.    ToolTip
  105.    Return
  106.  
  107.  
  108. Exit ; Everything above this line is run when the script is loaded.
  109.  
  110.  
  111. ; ============================================================
  112. ; FUNCTIONS & SUBROUTINES
  113. ; ============================================================
  114.  
  115. HardwareUpdate()
  116. {
  117.    Global MouseLast
  118.    Global MousePresent
  119.    Global CurrentName
  120.    Gosub, MouseCheck
  121.    ; We might get phantom hardware-change messages, so make sure the status
  122.    ; of the mouse has actually changed before changing any settings.
  123.    If MousePresent = %MouseLast%
  124.       Exit
  125.    Else
  126.    {
  127.       Gosub, ChangeSettings
  128.       MouseLast = %MousePresent%   ; Update mouse status.
  129.       ToolTip, Pointer Settings Changed To: %CurrentName%
  130.       Sleep, 2000
  131.       ToolTip
  132.    }
  133.    Return
  134. }
  135.  
  136. MouseCheck:
  137.    MousePresent = 0
  138.    Sleep, 1000   ; Give the registry a moment to update.
  139.    Loop, HKEY_LOCAL_MACHINE, SYSTEM\CurrentControlSet\Services\Mouclass\Enum, 0, 0
  140.    {
  141.       RegRead, CurrentValue
  142.       IfInString, CurrentValue, %MouseID%
  143.       {
  144.          MousePresent = 1
  145.          Break   ; Don't check any more values.
  146.       }
  147.    }
  148.    Return
  149.  
  150. ChangeSettings:
  151.    If MousePresent
  152.    {
  153.       CurrentName = %MouseName%
  154.       DeviceSpeed = %MouseSpeed%
  155.       DeviceEnhance = %MouseEnhance%
  156.       DeviceThreshold1 = %MouseThreshold1%
  157.       DeviceThreshold2 = %MouseThreshold2%
  158.       If TrayIcon and FileExist(MouseIcon)
  159.          Menu, Tray, Icon, %MouseIcon%, %MouseIconGroup%
  160.       Menu, Tray, Tip, Current Pointer Settings: %CurrentName%
  161.    }
  162.    Else
  163.    {
  164.       CurrentName = %PadName%
  165.       DeviceSpeed = %PadSpeed%
  166.       DeviceEnhance = %PadEnhance%
  167.       DeviceThreshold1 = %PadThreshold1%
  168.       DeviceThreshold2 = %PadThreshold2%
  169.       If TrayIcon and FileExist(PadIcon)
  170.          Menu, Tray, Icon, %PadIcon%, %PadIconGroup%
  171.       Menu, Tray, Tip, Current Pointer Settings: %CurrentName%
  172.    }
  173.  
  174.    VarSetCapacity(DeviceArray, 12, 0)
  175.    InsertInteger(DeviceThreshold1, DeviceArray, 0)   ; Reg. Value MouseThreshold1
  176.    InsertInteger(DeviceThreshold2, DeviceArray, 4)   ; Reg. Value MouseThreshold2
  177.    InsertInteger(DeviceEnhance, DeviceArray, 8)      ; Reg. Value MouseSpeed
  178.  
  179.    InsertInteger(pInteger, ByRef pDest, pOffset = 0, pSize = 4)
  180.    ; The caller must ensure that pDest has sufficient capacity.  To preserve any existing contents in pDest,
  181.    ; only pSize number of bytes starting at pOffset are altered in it.
  182.    {
  183.       Loop %pSize%  ; Copy each byte in the integer into the structure as raw binary data.
  184.          DllCall("RtlFillMemory", "UInt", &pDest + pOffset + A_Index-1, "UInt", 1, "UChar", pInteger >> 8*(A_Index-1) & 0xFF)
  185.    }
  186.  
  187.    ; Keep this here for future reference.
  188.    ; DllCall("SystemParametersInfo", UInt, SPI_GETMOUSESPEED, UInt, 0, UIntP, SpeedCurrent, UInt, 0)
  189.  
  190.    ; Change the pointer speed.
  191.    DllCall("SystemParametersInfo", UInt, SPI_SETMOUSESPEED, UInt, 0, UInt, DeviceSpeed, UInt, 1)
  192.    ; Change the pointer precision settings.
  193.    DllCall("SystemParametersInfo", UInt, SPI_SETMOUSE, UInt, 0, Str, DeviceArray, UInt, 1)
  194.    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,258
    • View Profile
    • Coding Snacks by Lanux128
    • Read more about this member.
    • Donate to Member
Re: mouse speed switcher
« Reply #4 on: April 04, 2008, 07:45:19 AM »
czechboy, would this script (or the original one) be helpful with this problem i'm having here?