Switch mouse DPI with keyboard?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Switch mouse DPI with keyboard?

14 Jul 2017, 15:32

Hey, I need a script that would let me to switch mouse DPI with keyboard. I do have a mouse that can switch DPI by own key, but I want to be able to do it with keyboard. Is it possible? Mouse is Logitech G203 and it's using Logitech Gaming Software(not SetPoint).
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

17 Jul 2017, 07:52

Little bump, got way behind without answer. I've seen many scripts being posted here but I would like it know if there's anything for changing DPI directly, not windows mouse sensitivity or using workaround like great "evilC's" script.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Switch mouse DPI with keyboard?

17 Jul 2017, 11:25

No, to my knowledge this is not technically feasible.
To which of my scripts are you referring? The demo on the MouseDelta thread can only add DPI when the script is activated, however I have a new script which can effectively subtract DPI
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

17 Jul 2017, 19:26

Yeah I was talking about mousedelta. This is the problem, top is delta, middle is delta in sniper mode and bottom is same mouse with DPI switch. From left to right DPI400/800/1200/1600.

Image
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

18 Jul 2017, 09:46

I got problems with launching it, CLR library missing.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Switch mouse DPI with keyboard?

18 Jul 2017, 09:50

See the comment in the first post:
evilC wrote:FOR ALL DEMOS IN THIS THREAD:

The SharpDX DLLs from SharpDX.zip in this post are required for the demos in all posts in this thread
You will need CLR.ahk from here
For each demo, extract the SharpDX DLLs from this post, plus the MouseDelta zip for that post into the same folder
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

18 Jul 2017, 11:43

Yes, it doesn't work this way. CLR.ahk doesn't launch, MouseDelta.ahk drops CLR error. Also even if it would launch, not sure how to change DPI.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Switch mouse DPI with keyboard?

18 Jul 2017, 11:50

You are not meant to launch CLR.ahk, it is an include for the script.

You want this demo, and you want to play around with this function in that script:

Code: Select all

MoveEvent(x, y, mouseId){
	Global mdw
	if (mdw.SelectedMouse == 0 || mdw.SelectedMouse == mouseId){
		DllCall("mouse_event",uint,1,int, x ,int, y,uint,0,int,0)
	}
}
ie something like the following should halve the sensitivity of your mouse:

Code: Select all

MoveEvent(x, y, mouseId){
	x := round(x / 2)
	y := round(y / 2)
	Global mdw
	if (mdw.SelectedMouse == 0 || mdw.SelectedMouse == mouseId){
		DllCall("mouse_event",uint,1,int, x ,int, y,uint,0,int,0)
	}
}
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

18 Jul 2017, 14:23

I'm not sure what I am doing wrong, but it throws me error: "0x2002000E invalid number of paramaters", "specifically SubsribeWheel" in current state:
; ================= USER SCRIPT ================
#SingleInstance force
#NoEnv
#include CLR.ahk
OnExit, UnhookAndClose

GoSub, Hook

Gui, Add, Text, , Select Mouse:
mdw := new MouseDeltaWrapper("x+5 yp-3 w200")
mdw.SubscribeMove(Func("MoveEvent"))
mdw.SubscribeWheel(Func("WheelEvent"))
Gui, Show
return

^Esc::
UnhookAndClose:
GuiClose:
GoSub, UnHook
ExitApp

Hook:
hHookMouse := SetWindowsHookEx(WH_MOUSE_LL := 14, RegisterCallback("MouseMove", "Fast"))
return

UnHook:
UnhookWindowsHookEx(hHookMouse)
return

MoveEvent(x, y, mouseId){
x := round(x / 2)
y := round(y / 2)
Global mdw
if (mdw.SelectedMouse == 0 || mdw.SelectedMouse == mouseId){
DllCall("mouse_event",uint,1,int, x ,int, y,uint,0,int,0)
}
}

WheelEvent(value, mouseId){
ToolTip % "Wheel: " value ", ID: " mouseId
}

; ================= WRAPPER LIBRARY ================
class MouseDeltaWrapper {
SeenMice := {}
SelectedMouse := 0
MoveCallback := 0

__New(guiOptions := "", dllPath := "MouseDelta.dll"){
this.Callback := callback

Gui, +HwndHwnd
this.GuiHwnd := Hwnd

Gui, Add, DDL, % "hwndhDDL " guiOptions, Any||
this.hDDL := hDDL

fn := this._UserSelectedMouse.Bind(this)
GuiControl, +g, % this.hDDL, % fn

asm := CLR_LoadLibrary(dllPath)
md := asm.CreateInstance("MouseDelta")

md.SubscribeRelativeMove(this._MoveEvent.Bind(this))
md.SubscribeWheel(this._WheelEvent.Bind(this))
this.md := md

this._UserSelectedMouse()
}

SubscribeMove(callback){
this.MoveCallback := callback
}

SubscribeWheel(callback){
this.WheelCallback := callback
}

_UserSelectedMouse(){
GuiControlGet, mouseId, , % this.hDDL
this.SelectedMouse := mouseId == "Any" ? 0 : mouseId
if (this.MoveCallback != 0)
this.md.SubscribeRelativeMove(this._MoveEvent.Bind(this), this.SelectedMouse)
if (this.WheelCallback != 0)
this.md.SubscribeWheel(this._WheelEvent.Bind(this), this.SelectedMouse)
}

_AddMouseToDDL(mouseId){
GuiControl, , % this.hDDL, % mouseId
}

_UpdateMice(mouseId){
if (!this.SeenMice.HasKey(mouseId)){
this.SeenMice[mouseId] := 1
this._AddMouseToDDL(mouseId)
}
}

_MoveEvent(x, y, mouseId){
this._UpdateMice(mouseId)
if (this.MoveCallback != 0 && (this.SelectedMouse == 0 || this.SelectedMouse == mouseId)){
this.MoveCallback.Call(x, y, mouseId)
}
}

_WheelEvent(value, mouseId){
this._UpdateMice(mouseId)
if (this.WheelCallback != 0 && (this.SelectedMouse == 0 || this.SelectedMouse == mouseId)){
this.WheelCallback.Call(value, mouseId)
}
}
}

MouseMove(nCode, wParam, lParam)
{
Critical
SetFormat, Integer, D
If !nCode && (wParam = 0x200){
; Mouse movement - process
if (NumGet(lParam+0, 12, "int")){
; if the LLMHF_INJECTED flag is set, this is "injected" input (Came from mouse_event)
; Let this input through
Return CallNextHookEx(nCode, wParam, lParam)
} else {
; Block the input
Return 1
}
} else {
; Other mouse message - let through
Return CallNextHookEx(nCode, wParam, lParam)
}
}

SetWindowsHookEx(idHook, pfn)
{
;Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", 0, "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

19 Jul 2017, 11:42

This is the error.

Image
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: Switch mouse DPI with keyboard?

19 Jul 2017, 13:18

Galvatron wrote:This is the error.
See this and this.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Switch mouse DPI with keyboard?

19 Jul 2017, 13:44

Grr, there is defo something wrong still with some of the attachments on that thread.
The Multi-Mouse version of MouseDelta.dll is still trying to load version 4..0.0.0 of SharpDX

Gimme a min, will see if I can sort it the hell out.
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

20 Jul 2017, 11:26

Thanks, no errors anymore but mouse sensitivity ain't changing, tried user and admin modes.
; ================= USER SCRIPT ================
#SingleInstance force
#NoEnv
#include CLR.ahk

Gui, Add, Text, , Select Mouse:
mdw := new MouseDeltaWrapper("x+5 yp-3 w200")
mdw.SubscribeMove(Func("MoveEvent"))
mdw.SubscribeWheel(Func("WheelEvent"))
Gui, Show
return

GuiClose:
ExitApp

MoveEvent(x, y, mouseId){
x := round(x / 4)
y := round(y / 4)
Global mdw
if (mdw.SelectedMouse == 0 || mdw.SelectedMouse == mouseId){
DllCall("mouse_event",uint,1,int, x ,int, y,uint,0,int,0)
}
}

WheelEvent(value, mouseId){
ToolTip % "Wheel: " value ", ID: " mouseId
}


; ================= WRAPPER LIBRARY ================
class MouseDeltaWrapper {
SeenMice := {}
SelectedMouse := 0
MoveCallback := 0

__New(guiOptions := "", dllPath := "MouseDelta.dll"){
this.Callback := callback

Gui, +HwndHwnd
this.GuiHwnd := Hwnd

Gui, Add, DDL, % "hwndhDDL " guiOptions, Any||
this.hDDL := hDDL

fn := this._UserSelectedMouse.Bind(this)
GuiControl, +g, % this.hDDL, % fn

asm := CLR_LoadLibrary(dllPath)
md := asm.CreateInstance("MouseDelta")

md.SubscribeRelativeMove(this._MoveEvent.Bind(this))
md.SubscribeWheel(this._WheelEvent.Bind(this))
this.md := md

this._UserSelectedMouse()
}

SubscribeMove(callback){
this.MoveCallback := callback
}

SubscribeWheel(callback){
this.WheelCallback := callback
}

_UserSelectedMouse(){
GuiControlGet, mouseId, , % this.hDDL
this.SelectedMouse := mouseId == "Any" ? 0 : mouseId
if (this.MoveCallback != 0)
this.md.SubscribeRelativeMove(this._MoveEvent.Bind(this), this.SelectedMouse)
if (this.WheelCallback != 0)
this.md.SubscribeWheel(this._WheelEvent.Bind(this), this.SelectedMouse)
}

_AddMouseToDDL(mouseId){
GuiControl, , % this.hDDL, % mouseId
}

_UpdateMice(mouseId){
if (!this.SeenMice.HasKey(mouseId)){
this.SeenMice[mouseId] := 1
this._AddMouseToDDL(mouseId)
}
}

_MoveEvent(x, y, mouseId){
this._UpdateMice(mouseId)
if (this.MoveCallback != 0 && (this.SelectedMouse == 0 || this.SelectedMouse == mouseId)){
this.MoveCallback.Call(x, y, mouseId)
}
}

_WheelEvent(value, mouseId){
this._UpdateMice(mouseId)
if (this.WheelCallback != 0 && (this.SelectedMouse == 0 || this.SelectedMouse == mouseId)){
this.WheelCallback.Call(value, mouseId)
}
}
}
Galvatron
Posts: 16
Joined: 11 Jun 2017, 09:52

Re: Switch mouse DPI with keyboard?

20 Jul 2017, 12:56

Tested now and it works good. But I can only do 1/2 mouse speed
x := round(x / 2)
y := round(y / 2)
Anything higher like 3,4 causes mouse to move in squares.

Also some toggle/hold button would be good. I guess for this extra script would be needed that would just enable/disable current one?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

Re: Switch mouse DPI with keyboard?

20 Jul 2017, 13:16

Nah, we can just add toggle functionality to the script, it's easy.
The likely reason why it does not work properly with higher values is that the majority of the values coming from the mouse will be low values. If dividing by 4, then if the mouse reports a move of 1,2,3 or 4 then it will be converted to 1.
You wanna set the DPI as high as possible, then turn down the sensitivity in the game. That way, it gives it more to work with.

To allow turning it on / off via a toggle, add this code:

Code: Select all

F1::
	toggle := !toggle
	return
Then adjust your MouseMove func like so:

Code: Select all


MoveEvent(x, y, mouseId){
	Global mdw
	Global toggle
	if (toggle){
		x := round(x / 4)
		y := round(y / 4)
	}
	if (mdw.SelectedMouse == 0 || mdw.SelectedMouse == mouseId){
		DllCall("mouse_event",uint,1,int, x ,int, y,uint,0,int,0)
	}
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: boydfields and 142 guests