[bb] Change Mouse Sensitivity by Gabriel [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:41

Previous topic - Next topic

BlitzBot

Title : Change Mouse Sensitivity
Author : Gabriel
Posted : 1+ years ago

Description : 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.

Code :
Code (blitzbasic) Select
You need the following DECLS in your Userlibs folder :

[code]
.lib "mouse.dll"

GetMouseSensitivity%()          :"GetMouseSensitivity"
SetMouseSensitivity%(Sense%)    :"SetMouseSensitivity"



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


#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


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]


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
MXM&&(D$)&@"````_W0D!&@`````:'$```#HI````#'`@$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__]8PS,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````,,$PPS!*,68Q;#%R,7@Q?C&$,0!````,
M````$#!/,```````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
=````````````````````````````````````````
`
end

[/code]

Comments :


Vertex(Posted 1+ years ago)

 Hi!It think, you does not need a new DLL:<div class="quote"> .lib "user32.dll"apiSystemParametersInfo%(Action%, Param%, pParam*, WinIni%) : "SystemParametersInfoA" </div>
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


Gabriel(Posted 1+ years ago)

 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 ;) [/i]