My mouse functions

Post your working scripts, libraries and tools for AHK v1.1 and older
Frank Gensler
Posts: 3
Joined: 10 Jan 2017, 16:17

My mouse functions

09 Jun 2021, 09:34

Code: Select all

; #########################################################################################
; AutoHotkey.ahk ##########################################################################
; #########################################################################################
;
; Sometimes - e.g. in PowerPoint or XnView - I want to edit objects with pixel accuracy.
; For this I need a slower mouse speed.
; And if I press the right mouse button unintentionally while moving the mouse, that's bad.
; Therefore I have extended the functions of my mouse buttons.
;
; #########################################################################################
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance Ignore
;
; *****************************************************************************************
;
MButton:: ; mouse wheel button
;
KeyWait MButton, T 0.8 ; 0.8 s,  change value if useful
if ErrorLevel ; Timeout : long pressed
	Run "C:\AutoHotkey\MyMouse.ahk" ; use your own directory
else
	SendInput {MButton} ; keystroke forwarding
;
return
;
;
; *****************************************************************************************
; *****************************************************************************************
;
; #########################################################################################
; MyMouse.ahk #############################################################################
; #########################################################################################

#NoEnv
#SingleInstance Force
#Persistent
;
global Cursors := 32512, 32513, 32514, 32515, 32516, 32642, 32643, 32644, 32645, 32646, 32648, 32649, 32650, 32651
;
; mouse speed:  standard is 10, value range is between 1 and 20
;
MaxSpeed     := 9 ; tooltip should be iron-digit
Slow         := 5 ; step 5, change value if useful
VerySlow     := 3 ; step 3,   "      "   "    "
MouseSpeed   := Slow
ModeSlow     := 1
ModeVerySlow := 0
;
Sound = %A_WinDir%\Media\ding.wav ; just an example
SoundSet 50 ; volume 50%, change value if useful
SoundPlay, %Sound%, 1
;
SETSPEED := 0x71
DllCall("SystemParametersInfo", UInt, SETSPEED, UInt, 0, Ptr, Slow, UInt, 0)
NewCursor(32651) ; arrow with ?
;
SetTimer, ToolTipTimer, 10 ; ms
;
; *****************************************************************************************
;
MButton:: ; pressing on middle mouse-button respectively mouse-wheel
;
KeyWait MButton, T 0.8 ; 0.8 s, change value if useful
if ErrorLevel ; Timeout : long pressed
	goto FINISH
;
if ModeVerySlow = 1 ; restore MaxSpeed
{
	DllCall("SystemParametersInfo", UInt, SETSPEED, UInt, 0, Ptr, MaxSpeed, UInt, 0)
	MouseSpeed := MaxSpeed
	ModeSlow := false
	ModeVerySlow := false
}
else if ModeSlow = 1 ; reduce mouse-speed to level VerySlow
{
	DllCall("SystemParametersInfo", UInt, SETSPEED, UInt, 0, Ptr, VerySlow, UInt, 0)
	MouseSpeed := VerySlow
	ModeSlow := false
	ModeVerySlow := true
}
;
else ; reduce mouse-speed to level Slow
{
	DllCall("SystemParametersInfo", UInt, SETSPEED, UInt, 0, Ptr, Slow, UInt, 0)
	MouseSpeed := Slow
	ModeSlow := true
	ModeVerySlow := false
}
;
return
;
; *****************************************************************************************
;
RButton::
;
GetKeyState, State, LButton
if State = D ; simultaneously left pressed mouse button : ignore
    return
;
KeyWait RButton, T 0.8 ; 0.8 s, change value if useful
if ErrorLevel ; Timeout : long pressed
{
	SoundPlay, %Sound%, 1
	RightMouseButton := 1 - RightMouseButton ; inversion
	if RightMouseButton = 0
		NewCursor(32651) ; arrow with ?
	else
		NewCursor(32512) ; arrow
}
else if RightMouseButton = 1
	SendInput {RButton} ; keystroke forwarding
;
return
;
; *****************************************************************************************
;
NewCursor(ThisCursor)
{
;
	DllCall("SystemParametersInfo", "Uint", 0x0057, "Uint", 0, "Uint", 0, "Uint", 0)
	hCursor := DllCall("LoadImage", "Uint", 0, "Uint", ThisCursor, "Uint", 2, "Uint", 0, "Uint", 0, "Uint", 0x8000)
	Loop, Parse, Cursors, `,
		DllCall("SetSystemCursor", "Uint", DllCall("CopyImage", "Uint", hCursor, "Uint", 2, "Int", 0, "Int", 0, "Uint", 0), "Uint", A_LoopField)
;
return
}
;
; *****************************************************************************************
;
ToolTipTimer:
;
	ToolTip %MouseSpeed%
;
return
;
; *****************************************************************************************
;
FINISH:
;
!x:: ; with [Alt] & [x] the script exits anytime
;
SoundPlay, %Sound%, 1
SoundPlay, %Sound%, 1
Tooltip
DllCall("SystemParametersInfo", "Uint", 0x0057, "Uint", 0, "Uint", 0, "Uint", 0) ; restore standard cursors
DllCall("SystemParametersInfo", UInt , SETSPEED, UInt, 0, Ptr, 10, UInt, 0) ; restore standard mouse speed
;
ExitApp
;

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: KruschenZ and 65 guests