Perfect WASD for joysticks

Post your working scripts, libraries and tools for AHK v1.1 and older
fodakahn
Posts: 2
Joined: 04 Dec 2013, 18:16

Perfect WASD for joysticks

04 Dec 2013, 18:27

and my first post!

This timer will save you much hassle if you intend to control a WASD game with a joystick, it even handles diagonals!

Code: Select all

     ;Perfect WASD by Fodakahn
	#Persistent
	SetTimer, joystick, 1
	
	joystick:
		getkeystate, 1JoyX, 1JoyX
		getKeystate, 1JoyY, 1JoyY
		
	    if (1JoyX > 40) and (1JoyX < 60) and (1JoyY > 40) and (1JoyY < 60) ;centered
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("W")
        Send {W up}
      if GetKeyState("S")
        Send {S up}

    }
    else if (1JoyX < 40) and (1JoyY > 60) ;down-left
    {
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("W")
        Send {W up}
      if !(GetKeyState("S"))
        Send {S down}
      if !(GetKeyState("A"))
        Send {A down}

    }
    else if (1JoyX < 40) and (1JoyY < 40) ;up-left
    {
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("S")
        Send {S up}
      if !(GetKeyState("W"))
        Send {W down}
      if !(GetKeyState("A"))
        Send {A down}

    }
    else if (1JoyX > 60) and (1JoyY < 40) ;up-right
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("S")
        Send {S up}
      if !(GetKeyState("W"))
        Send {W down}
      if !(GetKeyState("D"))
        Send {D down}

    }
    else if (1JoyX > 60) and (1JoyY > 60) ;down-right
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("W")
        Send {W up}
      if !(GetKeyState("S"))
        Send {S down}
      if !(GetKeyState("D"))
        Send {D down}

    }
    else if (1JoyX < 25) and (1JoyY > 40) and (1JoyY < 60) ;left
    {
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("W")
        Send {W up}
      if GetKeyState("S")
        Send {S up}
      if !(GetKeyState("A"))
        Send {A down}

    }
    else if (1JoyX > 75) and (1JoyY > 40) and (1JoyY < 60) ;right
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("W")
        Send {W up}
      if GetKeyState("S")
        Send {S up}
      if !(GetKeyState("D"))
        Send {D down}

    }
    else if (1JoyY > 75) and (1JoyX > 40) and (1JoyX < 60) ;down
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("W")
        Send {W up}
      if !(GetKeyState("S"))
        Send {S down}
    }
    else if (1JoyY < 25) and (1JoyX > 40) and (1JoyX < 60) ; up
    {
      if GetKeyState("A")
        Send {A up}
      if GetKeyState("D")
        Send {D up}
      if GetKeyState("S")
        Send {S up}
      if !(GetKeyState("W"))
        Send {W down}
    }
return

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: gongnl, jiming0516 and 83 guests