B2B Code Show: Mouse Restrictor Plate

Code and explanation by Kiyote Wolf

This code here, for freeBASIC, will let you control how much response you get from the mouse.

It takes a sample, waits a little bit, then takes a percentage of how much movement was made during that time.

It works by constantly re-entering the mouse.

I left the mouse cursor visible, so you could see the effects of what the code does to the system cursor, as it gives you a new more smooth riding cursor.

Smooth riding cursor. Available now at a FB depot near you.

SPECIAL NOTE: Due to the way this code operates, the slowed down cursor will only work in full screen applications. If you try to do it in a windowed screen, it just plain won't work. It will give wild uncontrollable results, as well as make your cursor within windows rooted to the center of the screen.

This has applications in image editing, because you can give your user a slider type control, to adjust both the X and Y percentage of mouse conditioning.

If you max it out to 100%, it will act like a normal mouse.

I have recently found out, that having a differing amount of X vs Y mouse conditioning control, may be more desirable. Your hand may have more precision when moving in an upwards downwards motion, but left to right, you may have a more pronounced movement, making such settings preferable.

dim shared MouseX as integer, MouseY as integer, MouseLeft as integer, MouseRight as integer
Dim Shared red As Integer, green As Integer, blue As Integer
declare function RGBclrout24 (clrin as integer) as longint 
declare sub Bounds(ByRef ValueIn As Integer, MinVal As integer,MaxVal As integer) 
declare sub SlowMouse (ScaleX As Integer, ScaleY as integer)
function RGBclrout24 (clrin as integer) as longint dim intin as integer, redin as integer, grnin as integer, bluin as integer, totalclr as longint 
     intin = (clrin and 8)\8 
     redin = (((clrin and 4) \ 4) * 31 + (15 * IntIn)) * 4
     grnin = (((clrin and 2) \ 2) * 31 + (15 * IntIn)) * 4
     bluin = ((clrin and 1) * 31 + (15 * IntIn)) * 4
     red = redin
     green = grnin
     blue = bluin
     RGBclrout24 = (clng(bluin) or (clng(grnin) shl 8) or (clng(redin) shl 16)) and &hFFFFFF
     '15: FF FF FF
     '14: FF FF 57
     '13: FF 57 FF
     '12: FF 57 57
     '11: 57 FF FF
     '10: 57 FF 57
     '9 : 57 57 FF
     '8 : 57 57 57
     '7 : AB AB AB
     '6 : AB 57 03
     '5 : AB 03 AB
     '4 : AB 03 03
     '3 : 03 AB AB
     '2 : 03 AB 03
     '1 : 03 03 AB
     '0 : 03 03 03
     select case clrin
     case 0 
          return rgb(03,03,03)
     case 1 
          return rgb(&h03,&h03, &hab) 
     case 2 
          return rgb(&h03,&hab,&h03) 
     case 3 
          return rgb(&h03, &hab, &hab) 
     case 4 
          return rgb(&hab, &h03, &h03) 
     case 5 
          return rgb(&hab, &h03, &hab)
     case 6 
          return rgb(&hab, &h57, &h03) 
     case 7 
        return rgb(&hab, &hab, &hab) 
     '15: FF FF FF
     '14: FF FF 57
     '13: FF 57 FF
     '12: FF 57 57
     '11: 57 FF FF
     '10: 57 FF 57
     '9 : 57 57 FF
     '8 : 57 57 57
     '7 : AB AB AB 
     case 8 
          return rgb(&h57,&h57,&h57)
     case 9
          return rgb(&h57,&h57,&hff) 
     case 10 
          return rgb(&h57,&hff,&h57) 
     case 11 
          return rgb(&h57,&hff,&hff) 
     case 12 
          return rgb(&hff,&h57,&h57) 
     case 13
          return rgb(&hff,&h57,&hff) 
     case 14 
          return rgb(&hff,&hff,&h57) 
     case 15 
          return rgb(&hff,&hff,&hff)
     end select
end function
sub Bounds(ByRef ValueIn As Integer, MinVal As integer,MaxVal As integer)
     If ValueIn < MinVal Then ValueIn = MinVal 
     If ValueIn > MaxVal Then ValueIn = MaxVal
End sub
sub SlowMouse (ScaleX As Integer, ScaleY as integer) 
     '<> Assume we are not normal 
     '[] Gravitate the normal cursor to a central position by averaging the current position 
     '[] Take a measured taste of the current vector of the mouse and return that data 
     '[] Calculate via ATN if necessary
     '[] Get mouse, take from center, divide out scale, return to center, return values, exit 
     'SetMouse ,,Abs(sgn(SysCursor(ScrnPage).MouseVisible))
     '<[KiyoteData]> 
     'SetMouse [x], [y], [visibility] 
     'x optional set x coordinate 
     'y optional set y coordinate 
     'visibility optional set visibility - 1 indicates visible, 0 indicates hidden 
     'Return Value 
     '0 on success, non-zero to indicate failure.  
     Dim MaxX As Integer, MaxY As Integer 
     Dim CenterX As Integer, CenterY As integer 
     Dim MseX As Integer, MseY As Integer, MseB As Integer, MseOk As integer
     Dim MseCalcX As Integer, MseCalcY As Integer 
     Dim Nul1 As integer 
     'If Active then MaxX = 640 
     MaxY = 480 
     CenterX = MaxX \ 2 
     CenterY = MaxY \ 2 
     Sleep 50,1 
     MseOk = GetMouse(MseX,MseY,,MseB) 
     If MseB And 1 Then 
          MouseLeft = -1 
     else 
          MouseLeft = 0 
     End If 
     If MseB And 2 Then 
          MouseRight = -1 
     else 
          MouseRight = 0 
     End if  
     SetMouse(CenterX,CenterY)  
     'If SysCursor(ScrnPage).WaitLetGo Then 
     ' Do 
     ' MseOk = GetMouse(Nul1,Nul1,,MseB) 
     ' Loop While MseB 
     'End if 
     MseCalcX = Int((MseX-CenterX) * (ScaleX/100)) 
     MseCalcY = Int((MseY-CenterY) * (ScaleY/100))  
     'Do not worry about MseOk 
     MouseX = MouseX + MseCalcX 
     MouseY = MouseY + MseCalcY 
     Bounds MouseX,0, 639 
     Bounds MouseY,0, 479  
     sleep 1,1 
End Sub
Screen 18,32,1,1
do 
    SlowMouse 30,50
    pset(MouseX,MouseY),RGBclrout24(15) 
loop until MouseRight
end