Joystick-like mouse?

Ask gaming related questions (AHK v1.1 and older)
notmyg
Posts: 1
Joined: 05 Feb 2020, 18:13

Joystick-like mouse?

05 Feb 2020, 18:32

Hello,
Is it possible with AHK to make a mouse behave like a joystick but not as an actual joystick? What I mean is that if the script was activated, the mouse cursor would be centered in it's current position and then the range limited in a circle around the centered position, and then return slowly back to center if the mouse was "released" (say from being still for 500ms)? There are several joystick to mouse scripts out there that work like this, like this one found here: https://autohotkey.com/board/topic/50344-help-with-joystick-and-a-mouse-movement-please/

Code: Select all

JoyMultiplier = 0.45
JoyThreshold =5
InvertYAxis := false
WheelDelay = 60
JoystickNumber = 1
#SingleInstance

JoyThresholdUpper := 50 + JoyThreshold
JoyThresholdLower := 50 - JoyThreshold

if InvertYAxis
    YAxisMultiplier = -1
else
    YAxisMultiplier = 1

SetTimer, WatchJoystick, 10  ; Monitor the movement of the joystick.
Return

;BUTTON 7 (delete command)
;Joy7::Send {Delete}
;Joy7::ExitApp

WatchJoystick:
   If ( xposOLD = "" or yposOLD = "" )
      MouseGetPos, xposOLD, yposOLD ; store the mouse position to restore later

   MouseNeedsToBeMoved := false  ; Set default.
   SetFormat, float, 03

   GetKeyState, joyx, %JoystickNumber%JoyX
   GetKeyState, joyy, %JoystickNumber%JoyY
   if joyx > %JoyThresholdUpper%
   {      
      MouseNeedsToBeMoved := true
      DeltaX := joyx - JoyThresholdUpper
   }
   else if joyx < %JoyThresholdLower%
   {
       MouseNeedsToBeMoved := true
       DeltaX := joyx - JoyThresholdLower
   }
   else
       DeltaX = 0

   if joyy > %JoyThresholdUpper%
   {
      MouseNeedsToBeMoved := true
      DeltaY := joyy - JoyThresholdUpper
   }
   else if joyy < %JoyThresholdLower%
   {
      MouseNeedsToBeMoved := true
      DeltaY := joyy - JoyThresholdLower
   }
   else
      DeltaY = 0
   
   if MouseNeedsToBeMoved
   {
      SendInput, {Alt Down}{MButton Down} ; I need to send this hotkey while I move the mouse with joystick   
      SetMouseDelay, -1  ; Makes movement smoother.
      MouseMove, DeltaX * JoyMultiplier * -1 ,DeltaY * JoyMultiplier * YAxisMultiplier, 0, R   
      ;BlockInput on

      SendInput, {MButton Up}{Alt Up}
      MouseGetPos Xpos, Ypos ; Get the position of the mouse
      Tooltip %xpos% %Ypos%
   }
   else ; if the mouse doesn't need to be moved, then joystick is back in the centre, so restore the mouse position
   {
      MouseMove, xposOLD, yposOLD, 0 ; move mouse instantly to old positions
      xposOLD := ""
      yposOLD := "" ; reset the old values so they are picked up next time
   }
return
That one works well for what I want the mouse to do, well it shows how the mouse should behave.
My idea is for a 3D game, so it couldn't use MouseMove. I tried to change the above script to use DLLCall(mouse_event) but for some reason it positions the cursor in the corner of the screen, but the cursor works fine with the joystick but just not with the mouse.
Anyways, my idea would be the mouse on a springy set of axis (for lack of a better word). If I moved the mouse down, the camera will move down in game but after a short amount of stopped mouse movement, the mouse would return to the center. This way I could walk around in game and look at things but then the camera would return to center.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 108 guests