Page 1 of 4

Changing mouse sensitivity

Posted: January 11th, 2018, 4:58 pm
by Unatomic
TL;DR: How to change mouse sensitivity instantly with rainmeter or with .bat or .vbs files?

Hello once again rainmeter community!!!

I am trying to use rainmeter to change mouse sensitivity. Something like "click and set sensitivity to 4."
Well because I don't think it can be done directly from rainmeter, I tried to use .bat files. (for some reason vbs don't work on my computer). What I found is that mouse sensitivity changes in registry with this command in batch:
reg add "HKCU\Control Panel\Mouse" /v MouseSensitivity /t REG_SZ /d "INSERT YOUR NUMBER HERE FROM 1 TO 20" /f

The problem is that while I see that the value changes in registry, the mouse sensitivity does not practically change. It changes only when I change it from mouse settings in control panel and press the APPLY or OK buttons. So my assumption is that I need to refresh the kernel driver from service controller or the mouhid service. That is what I have found so far but I am stuck. What should I do or what can be done?

Anyone else here tried changing mouse sensitivity with a single bat or vbs file??? Any other recommendations??? (Should I post this in a different section?)

Thanx everyone and have a nice day!

Re: Changing mouse sensitivity

Posted: January 11th, 2018, 6:42 pm
by balala
Unatomic wrote:The problem is that while I see that the value changes in registry, the mouse sensitivity does not practically change. It changes only when I change it from mouse settings in control panel and press the APPLY or OK buttons. So my assumption is that I need to refresh the kernel driver from service controller or the mouhid service. That is what I have found so far but I am stuck. What should I do or what can be done?

Anyone else here tried changing mouse sensitivity with a single bat or vbs file??? Any other recommendations??? (Should I post this in a different section?)
I'd try to use the nircmd app for a such task.
If you want to try my proposal, first you have to download the nircmd (supposing you didn't yet). Here it is (go to the bottom of the page): http://www.nirsoft.net/utils/nircmd.html
Unpack the downloaded package, then copy the nircmd folder to the @Resources folder of your skin.
If you did all these, now a following kind of meter I hope will help:

Code: Select all

[MeterSensitivity]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255
SolidColor=47,47,47
Padding=15,5,15,5
AntiAlias=1
Text=Change sensitivity
LeftMouseUpAction=["#@#nircmd\nircmd.exe" regsetval sz "HKCU\Control Panel\Mouse" "MouseSensitivity" "4"]
Obviously, you have to use as the last element above, the desired numeric value, of the sensitivity you'd like to set up.
Again: this solution works only if you have the nircmd software in the right place (in this case it is placed to @Resources\nircmd\nircmd.exe).
A while ago I've used this solution to modify another registry key and it worked then, without problems. Please let me know if this helped you.

Re: Changing mouse sensitivity

Posted: January 11th, 2018, 8:12 pm
by SilverAzide
Unatomic wrote:TL;DR: How to change mouse sensitivity instantly with rainmeter or with .bat or .vbs files?
You can use a powershell script to do this: https://gallery.technet.microsoft.com/scriptcenter/Controlling-Mouse-Speed-9ba16d0f

You can invoke powershell with the RunCommand plugin.

Re: Changing mouse sensitivity

Posted: January 11th, 2018, 8:13 pm
by jsmorley
SilverAzide wrote:You can use a powershell script to do this: https://gallery.technet.microsoft.com/scriptcenter/Controlling-Mouse-Speed-9ba16d0f

You can invoke powershell with the RunCommand plugin.
The trouble with using powershell with RunCommand is that a powershell console window will very briefly appear.

Re: Changing mouse sensitivity

Posted: January 12th, 2018, 1:01 am
by SilverAzide
jsmorley wrote:The trouble with using powershell with RunCommand is that a powershell console window will very briefly appear.
Aha! Not if you know the secret trick! ;) It's one of the handiest features of powershell.

The trick is the -NonInteractive switch; e.g., powershell -NonInteractive -Command "... your PS command..."

Code: Select all

[MeasureRunCmd]
Measure=Plugin
Plugin=RunCommand
Parameter="powershell -NonInteractive -Command "... your PS command..."
OutputType=ANSI
State=Hide
Timeout=5000
Another super handy feature of powershell is that you can get it to prompt for elevation, something you can't do with a command prompt (a command prompt has to be launched as an Admin, but a PS command can elevate a process as needed using the -Verb switch).

Here is a powershell command that will launch DOS-type batch file in an elevated hidden window (yes, you can launch a hidden powershell window that launches a hidden window). All you will see is a prompt for elevation.

powershell -NonInteractive -Command "Start-Process 'my_batch_file.cmd' [color=#FF0000]-Verb runAs[/color] -WindowStyle Hidden"

Re: Changing mouse sensitivity

Posted: January 12th, 2018, 1:16 am
by jsmorley
SilverAzide wrote:Aha! Not if you know the secret trick! ;) It's one of the handiest features of powershell.

The trick is the -NonInteractive switch; e.g., powershell -NonInteractive -Command "... your PS command..."

Code: Select all

[MeasureRunCmd]
Measure=Plugin
Plugin=RunCommand
Parameter="powershell -NonInteractive -Command "... your PS command..."
OutputType=ANSI
State=Hide
Timeout=5000
Another super handy feature of powershell is that you can get it to prompt for elevation, something you can't do with a command prompt (a command prompt has to be launched as an Admin, but a PS command can elevate a process as needed using the -Verb switch).

Here is a powershell command that will launch DOS-type batch file in an elevated hidden window (yes, you can launch a hidden powershell window that launches a hidden window). All you will see is a prompt for elevation.

powershell -NonInteractive -Command "Start-Process 'my_batch_file.cmd' [color=#FF0000]-Verb runAs[/color] -WindowStyle Hidden"
Ah, ok. Cool...

The real power is in .ps1 scripts. Have you worked out how to execute those with RunCommand and still get the results back in the measure with STDOUT without a console window?

Re: Changing mouse sensitivity

Posted: January 13th, 2018, 5:26 pm
by Unatomic
I tried both nircmd and vbs and I face the same problem. Mouse sensitivity changes in regedit key value, but mouse speed certainly does not. (I had used nircmd several times for some other skins so I know it works.)

Of course I tried to put extreme values like 2 or 18 to see a difference in the actual mouse speed but with no effect.
Screenshot_1.png
Just to mention that I found a way to set it with Autohotkey scripts compiled to .exe and called from rainmeter.
.ahk file: DllCall("SystemParametersInfo", Int,113, Int,0, UInt,"your-mouse-speed-here-in-number-without-quotes", Int,2)

But it is kind of limited.
First reason I can not change it fast enough (it can be done pretty fast but you know what I mean).
Second reason I can not adjust it dynamically. I have an idea to make a +button and a -button so I increase and decrease mouse speed for (lets say) +0.5 and -0.5 each time.

So I guess it has something to do with my computer because I tried several vb scripts, I tried your proposed vbs and nircmd commands and still nothing.
Still thank you for your help.

Re: Changing mouse sensitivity

Posted: January 13th, 2018, 5:39 pm
by SilverAzide
Did you try the Powershell script? That should do it; changing the registry only won't have any effect.

Re: Changing mouse sensitivity

Posted: January 13th, 2018, 7:49 pm
by Unatomic
Yes I tried the powershel. Thats what I say. Powershell vbs and nircmd command change the value but do not have an effect in actual mouse speed. :/

Re: Changing mouse sensitivity

Posted: January 17th, 2018, 4:24 pm
by balala
jsmorley wrote:The trouble with using powershell with RunCommand is that a powershell console window will very briefly appear.
I'm sorry, but I have to argue this. It doesn't appear at all.