Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; #INDEX# ===================================================================================================
- ; Title .........: wasdPOE
- ; Version........: 1.0
- ; Language ......: English
- ; Description ...: Keyboard movement script for the game Path of Exile.
- ; Author(s) .....: Stybbe
- ; ===========================================================================================================
- #include <WindowsConstants.au3>
- #include <GuiConstantsEx.au3>
- #include <Misc.au3>
- #include <GDIPlus.au3>
- #include <WinAPI.au3>
- Opt("MouseClickDragDelay",1)
- Opt("SendKeyDelay",0)
- Opt("SendKeyDownDelay",0)
- ;For list of keys see http://www.autoitscript.com/autoit3/docs/libfunctions/_IsPressed.htm
- $_up = "57" ; W
- $_left = "41" ; A
- $_down = "53" ; S
- $_right = "44" ; D
- $_MouseOffset = 65 ; offset from player in pixels the mouse move when using wasd-Keys.
- ; go to GetKeyBoardInput() function to change it more specific.
- $_extra_mouseBtn = "06" ;pressing this will also press mouse1.
- ;Used due to $_UseShiftOnLeftAttack conflict in inventory.
- $_move = "04" ; middle mouse
- $_moveMouse = "middle" ; should be same as above but in textform lol
- $_atk1 = "01" ; mouse1
- $_atk2 = "02" ; mouse2
- $_atk3 = "51" ; Q
- $_atk4 = "20" ; Space
- $_atk5 = "45" ; E
- $_atk6 = "52" ; R
- $_atk7 = "54" ; T
- HotKeySet("{F9}", "_Exit") ;The key that shut down this script
- ;Can also be closed by right clicking the Autoit icon in taskbar
- $_GoBackToOldPosMouse = True ;set to false if you dont want the mouse to move to the red mouse
- $_UseShiftOnLeftAttack = True ;set to false if you dont want to auto use shift on mouse1.
- $pngSrc = @ScriptDir & "\cursor.png" ;By default the cursor image need to be in same map as the script
- ;Only change stuff under here if you know what you doing
- Enum $up, $upRight, $right, $downRight, $down, $downLeft, $left, $upLeft
- Local $prevMousePos
- Local $hasMovedMouse = true
- Local $hasMovedChar = false
- Local $releaseShift = false
- Local $GameTitle = "Path of Exile"
- Local $ProgramTitle = "wasdPOEd"
- Local $POEhandle = HWnd(WinGetHandle($GameTitle))
- _GDIPlus_Startup()
- $GUI = _GUICreate_Alpha($ProgramTitle, $pngSrc)
- $myGuiHandle = WinGetHandle($ProgramTitle)
- WinSetOnTop($myGuiHandle,"",1)
- _WinAPI_SetWindowLong($myGuiHandle, -20, BitOR(_WinAPI_GetWindowLong($myGuiHandle, -20), $WS_EX_TRANSPARENT))
- $winSize = WinGetPos($ProgramTitle)
- $cursorXoffset = 0
- $cursorYoffset = 0
- GUISetState()
- $dll = DllOpen("user32.dll")
- $moved = False
- $isActive = True
- $goalX = 0
- $goalY = 0
- $fakeCursorX = 0
- $fakeCursorY = 0
- $prevDirection = 0
- $mouseDown_extra = False
- $isChatOpen_extra = False
- While 1
- If GUIGetMsg() = -3 then _Exit()
- extraInputs()
- if WinActive($GameTitle) Then
- if Not $isActive Then
- $isActive = True
- GUICtrlSetState(-1, $GUI_SHOW)
- WinSetOnTop($myGuiHandle,"",1)
- GUISetState()
- EndIf
- $mouse = MouseGetPos()
- ;move fake cursor
- WinMove($myGuiHandle,"",$fakeCursorX - $cursorXoffset,$fakeCursorY - $cursorYoffset)
- $currentDirection = GetKeyBoardInput()
- if $currentDirection[0] <> -1 Then
- $winPos = WinGetPos("[active]")
- $goalX = $winPos[2]/2 + $winPos[0] + $currentDirection[0]
- $goalY = $winPos[3]/2 + $winPos[1] + $currentDirection[1]
- if $hasMovedMouse And $_GoBackToOldPosMouse Then
- $hasMovedMouse = false
- ElseIf $currentDirection[0] == $prevDirection[0] And _
- $currentDirection[1] == $prevDirection[1] Then
- $fakeCursorX += $mouse[0] - $goalX
- $fakeCursorY += $mouse[1] - $goalY
- EndIf
- MouseMove($goalX, $goalY,0)
- MouseDown($_moveMouse)
- $hasMovedChar = true
- Else
- if $hasMovedChar Then
- if _IsPressed($_move) Then
- MouseUp($_moveMouse)
- ;Fixes bug in PoE where if two mouse buttons are down at same time
- ;and you release one. PoE will not register the other one you still
- ;holding down.
- if _IsPressed($_atk1, $dll) Then
- MouseDown("left")
- endif
- if _IsPressed($_atk2, $dll) Then
- MouseDown("right")
- endif
- EndIf
- $hasMovedChar = false
- EndIf
- if Not $hasMovedMouse and $_GoBackToOldPosMouse Then
- MouseMove($fakeCursorX,$fakeCursorY,0)
- $hasMovedMouse = True
- Else
- $fakeCursorX = $mouse[0]
- $fakeCursorY = $mouse[1]
- EndIf
- EndIf
- $prevDirection = $currentDirection
- Else
- if $isActive Then
- $isActive = False
- GUICtrlSetState(-1, $GUI_HIDE)
- EndIf
- EndIf
- WEnd
- Func extraInputs()
- ;Extra mouse button
- if _IsPressed($_extra_mouseBtn, $dll) Then
- MouseDown("left")
- $mouseDown_extra = true
- Elseif $mouseDown_extra Then
- MouseUp("left")
- $mouseDown_extra = False
- EndIf
- ;Pause wasd-keys if typing in chat.
- if WinActive($GameTitle) Then
- if _IsPressed("0D", $dll) Then
- $isChatOpen_extra = Not $isChatOpen_extra
- EndIf
- EndIf
- EndFunc
- ;pos[0] = X-offset pixels from the middle position of the Path of Exile window
- ;pos[1] = Y-offset pixels from the middle position of the Path of Exile window
- ;Change the offset to whatever.
- Func GetKeyBoardInput()
- Local $pos[2] = [-1,-1]
- if _IsPressed($_atk1,$dll) And Not $mouseDown_extra then
- if $_UseShiftOnLeftAttack Then
- if Not $releaseShift Then
- Send("{SHIFTDOWN}")
- $releaseShift = True
- EndIf
- EndIf
- return $pos
- EndIf
- if $isChatOpen_extra Or _
- _IsPressed($_atk2,$dll) Or _
- _IsPressed($_atk3,$dll) Or _
- _IsPressed($_atk4,$dll) Or _
- _IsPressed($_atk5,$dll) Or _
- _IsPressed($_atk6,$dll) Or _
- _IsPressed($_atk7,$dll) _
- Then
- ;break movement if any atk key is pressed.
- return $pos
- EndIf
- if $_UseShiftOnLeftAttack Then
- if $releaseShift Then
- $releaseShift = False
- Send("{SHIFTUP}")
- EndIf
- EndIf
- if _IsPressed($_up,$dll) And _IsPressed($_right,$dll) Then
- $pos[0] = $_MouseOffset
- $pos[1] = -$_MouseOffset
- return $pos
- EndIf
- if _IsPressed($_up,$dll) And _IsPressed($_left,$dll) Then
- $pos[0] = -$_MouseOffset
- $pos[1] = -$_MouseOffset
- return $pos
- EndIf
- if _IsPressed($_down,$dll) And _IsPressed($_left,$dll) Then
- $pos[0] = -$_MouseOffset
- $pos[1] = $_MouseOffset
- return $pos
- EndIf
- if _IsPressed($_down,$dll) And _IsPressed($_right,$dll) Then
- $pos[0] = $_MouseOffset
- $pos[1] = $_MouseOffset
- return $pos
- EndIf
- if _IsPressed($_left,$dll)Then
- $pos[0] = -$_MouseOffset
- $pos[1] = 0
- return $pos
- EndIf
- if _IsPressed($_right,$dll)Then
- $pos[0] = $_MouseOffset
- $pos[1] = 0
- return $pos
- EndIf
- if _IsPressed($_up,$dll)Then
- $pos[0] = 0
- $pos[1] = -$_MouseOffset
- return $pos
- EndIf
- if _IsPressed($_down,$dll)Then
- $pos[0] = 0
- $pos[1] = $_MouseOffset
- return $pos
- EndIf
- return $pos
- EndFunc
- ;the cursor is a .png GUI and it need this function to initialize
- Func _GUICreate_Alpha($sTitle, $sPath, $iX=-1, $iY=-1, $iOpacity=255)
- Local $hGUI, $hImage, $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
- $hImage = _GDIPlus_ImageLoadFromFile($sPath)
- $width = _GDIPlus_ImageGetWidth($hImage)
- $height = _GDIPlus_ImageGetHeight($hImage)
- $hGUI = GUICreate($sTitle, $width, $height, $iX, $iY, $WS_POPUP, $WS_EX_LAYERED)
- $hScrDC = _WinAPI_GetDC(0)
- $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
- $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
- $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
- $tSize = DllStructCreate($tagSIZE)
- $pSize = DllStructGetPtr($tSize)
- DllStructSetData($tSize, "X", $width)
- DllStructSetData($tSize, "Y", $height)
- $tSource = DllStructCreate($tagPOINT)
- $pSource = DllStructGetPtr($tSource)
- $tBlend = DllStructCreate($tagBLENDFUNCTION)
- $pBlend = DllStructGetPtr($tBlend)
- DllStructSetData($tBlend, "Alpha", $iOpacity)
- DllStructSetData($tBlend, "Format", 1)
- _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
- _WinAPI_ReleaseDC(0, $hScrDC)
- _WinAPI_SelectObject($hMemDC, $hOld)
- _WinAPI_DeleteObject($hBitmap)
- _WinAPI_DeleteObject($hImage)
- _WinAPI_DeleteDC($hMemDC)
- EndFunc ;==>_GUICreate_Alpha
- Func _Exit()
- MouseUp($_moveMouse)
- _GDIPlus_Shutdown()
- GUIDelete($GUI)
- DllClose($dll)
- Exit
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement