C
C#5mo ago
Itskillerluc

cant set enhanced mouse precision

Ok i still don’t have the mouse thing working. I’m trying to set the enhanced mouse position option using code. I first get the mouse settings array using systemparameterinfo, that works I get the right values in the array. I then set the last value from a 0 to a 1 to turn the setting on and vice versa to turn it off, I put that in the setmouse in systemparametersinfo with a 2 to supposedly update the mouse in the last parameter, but literally nothing happens I have no clue why this does not work because I’m doing the same things as I find online Only online they just use the constant for the updating, I am like 50% certain it’s 2 tho it’s super hard to actually find Do I also have to set the registry value for this to work?
18 Replies
Itskillerluc
Itskillerluc5mo ago
Anyone any idea? @Tanner Gooding if you have time would appreciate it if you could help. Ofc it’s fine if you can’t.
tannergooding
tannergooding5mo ago
can you share the code you're using and what you expect to happen? it sounds like you're trying to turn mouse acceleration on/off but afair, acceleration is a value between 0 and 20 with 10 being the default
tannergooding
tannergooding5mo ago
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event describes how the thresholds and acceleration parameter work in coordination with eachother
mouse_event function (winuser.h) - Win32 apps
The mouse_event function synthesizes mouse motion and button clicks.
Itskillerluc
Itskillerluc5mo ago
Yep Well the value from 1-20 is the mouse speed which is different, you set the speed wirh set mouse speed. The actual mouse acceleration curve I can’t find how to set but it’s not with any of these functions. What I mean is the enhancement precision flag which is either true or false
Itskillerluc
Itskillerluc5mo ago
the slider is the 1-20 mouse speed, the checkbox is the mouse acceleration which im trying to change
No description
Itskillerluc
Itskillerluc5mo ago
[LibraryImport("user32", EntryPoint = "SystemParametersInfoW")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool SystemParametersInfo(uint uiAction, uint uiParam, [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] int[] pvParam, uint fwinIni);

const uint SPI_GETMOUSE = 0x0003;
const uint SPI_SETMOUSE = 0x0004;

public static void SetEnhancedPrecision(bool precision)
{
var mouseInfo = new int[3];
var flag = SystemParametersInfo(SPI_GETMOUSE, 0, mouseInfo, 0);
foreach (int i in mouseInfo)
{
Console.Out.WriteLine(i);
}
if (flag)
{
mouseInfo[2] = (mouseInfo[2] * (precision ? 1 : 0));
SystemParametersInfo(SPI_SETMOUSE, 0, mouseInfo, 0x02);
}
}
[LibraryImport("user32", EntryPoint = "SystemParametersInfoW")]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool SystemParametersInfo(uint uiAction, uint uiParam, [MarshalAs(UnmanagedType.LPArray, SizeConst = 3)] int[] pvParam, uint fwinIni);

const uint SPI_GETMOUSE = 0x0003;
const uint SPI_SETMOUSE = 0x0004;

public static void SetEnhancedPrecision(bool precision)
{
var mouseInfo = new int[3];
var flag = SystemParametersInfo(SPI_GETMOUSE, 0, mouseInfo, 0);
foreach (int i in mouseInfo)
{
Console.Out.WriteLine(i);
}
if (flag)
{
mouseInfo[2] = (mouseInfo[2] * (precision ? 1 : 0));
SystemParametersInfo(SPI_SETMOUSE, 0, mouseInfo, 0x02);
}
}
wiat im dumb why do i multiply itll always be 0
tannergooding
tannergooding5mo ago
that last parameter, 0x02 corresponds to SPIF_SENDCHANGE which ensures that WM_SETTINGSCHANGE gets sent out
Itskillerluc
Itskillerluc5mo ago
ill feel so dumb if that fixes it It should ye i had a REALLY hard time finding it but i think its 2
tannergooding
tannergooding5mo ago
it's 2, it's defined in um\WinUser.h
Itskillerluc
Itskillerluc5mo ago
omg i got it working now 💀 iim so soryy this was so dumb of me its because i multiply so if its 0 it will always stay 0 idk why i multiplied
tannergooding
tannergooding5mo ago
I believe you can set the mouse speed with mouseInfo[2] and SPI_SETMOUSE as well. That's exactly how the example given on the SystemParametersInfoW doc page shows it
Itskillerluc
Itskillerluc5mo ago
letme try
tannergooding
tannergooding5mo ago
SPI_SETMOUSE documents itself as
Sets the two mouse threshold values and the mouse acceleration. The pvParam parameter must point to an array of three integers that specifies these values.
Itskillerluc
Itskillerluc5mo ago
well ye mouseInfo[1] corresponds to the speed value that is a value between 1-20 or well it is 10 mhhhm mabe it does change soemthing i feel like it does not tho i dont notice any difference in speed
tannergooding
tannergooding5mo ago
Well, https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-mouse_event#remarks describes how acceleration works and the example given here shows multiplying mouseInfo[2], so it seems more than just 0/1 https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-systemparametersinfow#examples I think it remains different from mouse speed itself
Itskillerluc
Itskillerluc5mo ago
well if i have speed at 20 and acceleration at 0 its faster than speed at 20 and acceleration at 1 or at 20 i am not sure the example cant be wrong right?
tannergooding
tannergooding5mo ago
it looks like acceleration acts as a scale and that 0, 1, and 2 might be valid values depending on how you interpret docs
If the specified distance along either the x or y axis is greater than the first mouse threshold value, and the mouse acceleration level is not zero, the operating system doubles the distance.
If the specified distance along either the x- or y-axis is greater than the second mouse threshold value, and the mouse acceleration level is equal to two, the operating system doubles the distance that resulted from applying the first threshold test
It is thus possible for the operating system to multiply relatively-specified mouse motion along the x- or y-axis by up to four times.
Itskillerluc
Itskillerluc5mo ago
ah well it atleast works how i want it to now so thats nice
Want results from more Discord servers?
Add your server
More Posts