#InstallKeybdHook

#SingleInstance Force

; Elecom Sniper Script

; This script lets you cycle DPI values in Windows

; It uses Japanese keyboard keybinds in order to not conflict with any normal US keyboard keybinds

; THIS SCRIPT IS BEST VIEWED IN SOMETHING LIKE NOTEPAD++ THAT SUPPORTS JAPANESE CHARACTERS

; To use this AHK script...

; 1. Install Elecom Mouse Assistant 5 (v5.1.13.000 or later)

; https://www.elecom.co.jp/global/download-list/utility/mouse_assistant/win/

; 2. Open the Mouse Assistant Settings Panel (and become familiar with the layout of this tool)

; 3. Switch the language to Japanese (because the keybinds won't work right in any other language)

; 4. Rebind any button to Arbitrary Key "任意キー"

; 5. Bind Half/Full (半角/全角) to the button you want to use to slow down the DPI

; 6. Bind Katakana/Hiragana (カタカナ/ひらがな) to the button you want to use to cycle the DPI

; 7. Customize this script

;

; Alternately, you can use this XML file to import Japanese settings for the Ex-G Pro

; https://pastebin.com/rnbsPMfx

;

; The following script is also useful for setting arbitrary keys and debugging them

; https://pastebin.com/xSwW7gxf

; Mouse Speed: use 1 to 20, default is 10

; !!! ADJUST THESE !!!

MouseSpeedSetpoint := Array ( 5 , 10 , 15 )

SniperMouseSpeed := 1

StartupMouseSpeed := 10

; SystemParametersInfo

SPI_GetMouseSpeed := 0x70

SPI_SetMouseSpeed := 0x71

; Variables

OriginalMouseSpeed := 0

CurrentMouseSpeed := 0

CurrentSetpointSpeed := 0

NewMouseSpeed := 0

FinalMouseSpeed := 0

; Startup mouse speed

CurrentSetpointSpeed := StartupMouseSpeed

DllCall ( "SystemParametersInfo" , UInt , SPI_SetMouseSpeed , UInt , 0 , UInt , CurrentSetpointSpeed , UInt , 0 )

ShowTrayTip ( )

; -----------------------------------------------------------------------------

; vk1C Convert = 前変換 = Not Used

;~ vk1C::

;~ {

;~ return

;~ }

; vk1D No_Conversion = 無変換 = Not Used

;~ vk1D::

;~ {

;~ return

;~ }

; -----------------------------------------------------------------------------

; UNCOMMENT IF YOU WANT TO HOLD DOWN THE BUTTON FOR SNIPER MODE

; vk19 Half/Full = 半角/全角 = Sniper Mode - Drop DPI down to a minimum value while the mouse key is held down

;~ vk19::

;~ {

;~ ; Get original mouse speed

;~ DllCall("SystemParametersInfo", UInt, SPI_GetMouseSpeed, UInt, 0, UIntP, OriginalMouseSpeed, UInt, 0)

;~ ; Set sniper mouse speed

;~ DllCall("SystemParametersInfo", UInt, SPI_SetMouseSpeed, UInt, 0, UInt, SniperMouseSpeed, UInt, 0)

;~ ToolTip, Sniper %OriginalMouseSpeed%/%SniperMouseSpeed%

;~ ; Wait for the sniper mode key to be released

;~ KeyWait, vk19, L ; !!! CHANGE KEY TO THE THIRD KEYSTROKE !!!

;~ ToolTip, Sniper Release %OriginalMouseSpeed%/%SniperMouseSpeed%

;~ ; Restore original mouse speed

;~ DllCall("SystemParametersInfo", UInt, 0x71, UInt, 0, UInt, OriginalMouseSpeed, UInt, 0)

;~ return

;~ }

; -----------------------------------------------------------------------------

; vk19 Half/Full = 半角/全角 - Sniper Mode - Drop DPI down to a minimum value and then restore it

vk19::

{

; Get original mouse speed

DllCall ( "SystemParametersInfo" , UInt , SPI_GetMouseSpeed , UInt , 0 , UIntP , CurrentMouseSpeed , UInt , 0 )

if ( CurrentMouseSpeed = SniperMouseSpeed )

{

NewMouseSpeed := CurrentSetpointSpeed

}

else

{

NewMouseSpeed := SniperMouseSpeed

}

; Set sniper mouse speed

DllCall ( "SystemParametersInfo" , UInt , SPI_SetMouseSpeed , UInt , 0 , UInt , NewMouseSpeed , UInt , 0 )

;~ ShowTrayTip()

return

}

; -----------------------------------------------------------------------------

; vk15 Katakana/Hiragana = カタカナ/ひらがな = DPI Cycle - Cycle through DPI values

vk15::

{

; Get current mouse speed

DllCall ( "SystemParametersInfo" , UInt , SPI_GetMouseSpeed , UInt , 0 , UIntP , CurrentMouseSpeed , UInt , 0 )

CurrentSetpointSpeed := - 1

; For each setpoint...

for key , Setpoint in MouseSpeedSetpoint

{

; If current mouse speed is less than the setpoint...

if ( CurrentMouseSpeed < Setpoint )

{

; Assign the setpoint and break out of the loop

CurrentSetpointSpeed := Setpoint

break

}

}

; If NewMouseSpeed has not been set, set it to setpoint 1

if ( 0 >= CurrentSetpointSpeed )

{

CurrentSetpointSpeed := MouseSpeedSetpoint [ 1 ]

}

; Force speed to 20 if speed is greater than 20.

if ( CurrentSetpointSpeed > 20 )

{

CurrentSetpointSpeed := 20

}

; Force speed to 1 if speed is less than 1.

if ( CurrentSetpointSpeed < 1 )

{

CurrentSetpointSpeed := 1

}

; Set new mouse speed

DllCall ( "SystemParametersInfo" , UInt , SPI_SetMouseSpeed , UInt , 0 , UInt , CurrentSetpointSpeed , UInt , 0 )

ShowTrayTip ( )

return

}

;~ F9::Reload

; -----------------------------------------------------------------------------

HideTrayTip ( )

{

TrayTip ; Attempt to hide it the normal way.

if SubStr ( A_OSVersion , 1 , 3 ) = "10." {

Menu Tray , NoIcon

Sleep 500 ; It may be necessary to adjust this sleep.

Menu Tray , Icon

}

return

}

ShowTrayTip ( )

{

global SPI_GetMouseSpeed

; Display Traytip

HideTrayTip ( )

DllCall ( "SystemParametersInfo" , UInt , SPI_GetMouseSpeed , UInt , 0 , UIntP , CurrentMouseSpeed , UInt , 0 )

TrayTip , Mouse Sensitivity , Mouse Sensitivity set at %CurrentMouseSpeed% ...

return