Code archives/User Input/Change Mouse Sensitivity

This code has been declared by its author to be Public Domain code.

Download source code

Change Mouse Sensitivity by Gabriel2005
Blitz doesn't let you change the mouse sensitivity, but Windows does. With a couple of API calls you can retrieve the current user setting, change it for your game, and put it back again at the end. It's a hack, but it's vital for certain purposes and the worst possible outcome is a crashed exe doesn't put the sensitivity back right.
You need the following DECLS in your Userlibs folder :

[code]
.lib "mouse.dll"

GetMouseSensitivity%()          :"GetMouseSensitivity"
SetMouseSensitivity%(Sense%)    :"SetMouseSensitivity"
[/code]


You also need my mouse DLL, written in PureBasic. If you have PureBasic, you can compile the following source to a DLL :

[code]
#SPI_GETMOUSESPEED=112
#SPI_SETMOUSESPEED=113

ProcedureDLL.l GetMouseSensitivity()
  MouseSpeed.l=0
  SystemParametersInfo_(#SPI_GETMOUSESPEED,0,@MouseSpeed,#SPIF_SENDWININICHANGE)
  ProcedureReturn MouseSpeed
EndProcedure 

ProcedureDLL SetMouseSensitivity(Sense.l)
  SystemParametersInfo_(#SPI_SETMOUSESPEED,0,Sense,#SPIF_SENDWININICHANGE)
EndProcedure
[/code]

If you don't have PureBasic, you can use this UUEncoded data to reproduce the DLL. Credits to Perturbatio for the Encoded DLL and link to the Decoder.

To turn this code into a DLL, you'll need a UUDecoder, which can be found here : [a http://www.bastet.com/software/software.html]http://www.bastet.com/software/software.html[/a]

[code]
begin 0666 mouse.dll
M35J0``,````$````__\``+@`````````0```````````````````````````
M````````````````````@`````X?N@X`M`G-(;@!3,TA5&AI<R!P<F]G<F%M
M(&-A;FYO="!B92!R=6X@:6X@1$]3(&UO9&4N#0T*)`````````!010``3`$%
M`*)]DT(``````````.``#B$+`0(R``0````&`````````!`````0````(```
M````$``0`````@``!``````````$``````````!@````!`````````,`````
M`!```!``````$```$````````!``````(```;@`````P``!0````````````
M`````````````````````````%```"@`````````````````````````````
M``````````````````````````````````````!T,```)```````````````
M`````````````````````"YT97AT````B`$````0`````@````0`````````
M`````````"```&`N<F1A=&$``&X`````(`````(````&````````````````
M``!```!`+F1A=&$````D`0```#`````"````"```````````````````0```
MP"YF;&%T````6@````!``````@````H``````````````````&```.`N<F5L
M;V,``"@`````4`````(````,``````````````````!```!"````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````(-\)`@!=0Z+1"0$
MHQPQ`!#H(@```(-\)`@"=0"#?"0(`'4%Z,0```"#?"0(`W4`N`$```#"#`!H
M`````&B@#P``:`````#H'P$``*,8,0`0ZTY345565XGF@^P$B>")PH/"!,<`
M`````(/`!#G0=?/'!"0`````:`(```"-1"0$4&@`````:'````#H\@```(L$
M).L",<"#Q`1?7EU96\/K25-15597B>:#[`2)X(G"@\($QP``````@\`$.=!U
M\XM&&(D$)&@"````_W0D!&@`````:'$```#HI````#'`@\0$7UY=65O"!`##
MZ`P```#_-1@Q`!#H=````,/#S,Q5B>535E>+70B+?0Q0ZT>#/_YU)3'VZQ?_
M=Q")\`^O1PR+5P@!V@'04.C2____1CMW!'SD@\<4ZQV+!X,\`P!T$HL'_S0#
M:@#_-1@Q`!#H*0```(/'!(,__W6T6%]>6UW""```_R5T,``0_R5\,``0_R6`
M,``0_R6$,``0_R6(,``0_R60,``0````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````*)]DT(`````/"````$````"`````@```"@@```P(```."``
M`%(0``"B$```1B```%H@``````$`;6]U<V4N9&QL`$=E=$UO=7-E4V5N<VET
M:79I='D`4V5T36]U<V5396YS:71I=FET>0``````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M``````````````````````````````!0,`````````````"B,```=#```%@P
M`````````````.0P``!\,```;#``````````````"C$``)`P````````````
M`````````````````)@P````````KC```+PP``#*,```V#````````#R,```
M`````)@P````````KC```+PP``#*,```V#````````#R,```````````;65M
M<V5T``!#4E1$3$PN9&QL`````$AE87!#<F5A=&4`````2&5A<$1E<W1R;WD`
M``!%>&ET4')O8V5S<P```$AE87!&<F5E``!+15).14PS,BY$3$P`````4WES
M=&5M4&%R86UE=&5R<TEN9F]!`%5315(S,BYD;&P`````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````````````````````````````````````````%`)TG04
M@^H44F@`````_S48,0`0Z&/1__]8P\S,S,S,4`G2=#.#ZA125E>+0@2+<@R+
M.H/"%%)04%+HP=#__UA:`?I.=?!?7F@`````_S48,0`0Z"31__]8PP``````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M`````````````````!```!P````,,$PP\S!*,68Q;#%R,7@Q?C&$,0!````,
M````$#!/,```````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
=````````````````````````````````````````
`
end

[/code]

Comments

Vertex2005
Hi!
It think, you does not need a new DLL:
.lib "user32.dll"
apiSystemParametersInfo%(Action%, Param%, pParam*, WinIni%) : "SystemParametersInfoA"



Const SPI_GETMOUSESPEED     = 112
Const SPI_SETMOUSESPEED     = 113
Const SPIF_SENDWININICHANGE = 2

Function GetMouseSpeed%()
	Local TempSpeed%, Speed%
	
	TempSpeed% = CreateBank(4)
	apiSystemParametersInfo(SPI_GETMOUSESPEED, 0, TempSpeed%, 0)
	Speed% = PeekInt(TempSpeed%, 0)
	
	FreeBank TempSpeed%
	Return Speed%
End Function

Function SetMouseSpeed(Speed%)
	Local TempSpeed%, Flags%
	
	TempSpeed% = CreateBank(4)
	PokeInt TempSpeed%, 0, Speed%
	
	Flags% = SPIF_SENDWININICHANGE
	apiSystemParametersInfo(SPI_SETMOUSESPEED, 0, TempSpeed%, Flags)

	FreeBank TempSpeed%
End Function


cu olli


Gabriel2005
Yep, that looks like it should work. Can you believe I've completed several games in Blitz and never once used banks? I guess I just never found a use for them. Until now ;)


Code Archives Forum