Jump to content

Recommended Posts

Posted (edited)

Hey all i found >this old script by Oxin8 for the X-box controller, but i just needed something more simple, so i decided to make a UDF simmilair to the _IsPressed function by ezzetabi and Jon.
Hope its helpfull to someone :-)

Functions:

  Reveal hidden contents

_IsPressed360


Example:

  Reveal hidden contents


UDF:

  Reveal hidden contents

Edited by Carlo84
Posted (edited)

Heres a better example.

Script uses Controller as mouse.

Press Escape to exit script.

Check here for button layout

Posted Image

#include "_IsPressed360.au3"
HotKeySet('{ESC}', '_Exit')
Global Const $hDll = DllOpen("xinput9_1_0.dll")
Global $iAdown = 0, $iBdown = 0, $iYDown = 0
Global $iLeftJoyDown = 0
Global $iLeftDown = 0, $iRightDown = 0, $iUpDown = 0, $iDownDown = 0
Global $iRightJoyRightDown = 0, $iRightJoyLeftDown = 0, $iRightJoyDown = 0, $iRightJoyUpDown = 0, $iRightJoyDownDown = 0

While 1
    If _IsPressed360(131072, $hDll) Or _IsPressed360(262144) Then _MouseMove() ; Left Joystick moved
    _MouseUpDown(64, 'middle', $iLeftJoyDown, $hDll) ; Left Joystick pressed

    _MouseUpDown(4096, 'primary', $iAdown, $hDll) ;A button
    _MouseUpDown(8192, 'secondary', $iBdown, $hDll) ;B button
    _KeyUpDown(-32768, '{LAUNCH_MEDIA down}', $iYDown, $hDll) ;Y button

    If _IsPressed360(16, $hDll) Then ; Start button pressed
        Send('#d')
        Sleep(1000)
    EndIf

    If _IsPressed360(32768, $hDll) Then MouseWheel('down') ; Left trigger pressed
    If _IsPressed360(65536, $hDll) Then MouseWheel('up') ; Right trigger pressed
    If _IsPressed360(256, $hDll) Then Send('{VOLUME_DOWN}') ; LB pressed
    If _IsPressed360(512, $hDll) Then Send('{VOLUME_UP}') ; RB pressed

    _KeyUpDown(1, '{MEDIA_PLAY_PAUSE down}', $iUpDown, $hDll) ;D-Pad Up button
    _KeyUpDown(2, '{MEDIA_STOP down}', $iDownDown, $hDll) ;D-Pad Down button
    _KeyUpDown(4, '{MEDIA_PREV down}', $iLeftDown, $hDll) ;D-Pad Left button
    _KeyUpDown(8, '{MEDIA_NEXT down}', $iRightDown, $hDll) ;D-Pad Right button

    If _IsPressed360(524288, $hDll) And @extended > 0 Then
        _KeyUpDown(524288, '{BROWSER_FORWARD down}', $iRightJoyRightDown, $hDll) ;Right Joystick moved to right
    ElseIf _IsPressed360(524288, $hDll) And @extended < 0 Then
        _KeyUpDown(524288, '{BROWSER_BACK down}', $iRightJoyLeftDown, $hDll) ;Right Joystick moved to left
    Else
        _KeyUpDown(524288, '{BROWSER_BACK down}', $iRightJoyLeftDown, $hDll) ;Right Joystick moved to left
        _KeyUpDown(524288, '{BROWSER_FORWARD down}', $iRightJoyRightDown, $hDll) ;Right Joystick moved to right
    EndIf
    _KeyUpDown(128, '{BROWSER_HOME down}', $iRightJoyDown, $hDll) ;Right Joystick pressed
    If _IsPressed360(1048576, $hDll) And @extended > 0 Then
        _KeyUpDown(1048576, '{BROWSER_FAVORITES down}', $iRightJoyUpDown, $hDll) ;Right Joystick moved up
    ElseIf _IsPressed360(1048576, $hDll) And @extended < 0 Then
        _KeyUpDown(1048576, '{BROWSER_REFRESH down}', $iRightJoyDownDown, $hDll) ;Right Joystick moved down
    Else
        _KeyUpDown(1048576, '{BROWSER_FAVORITES down}', $iRightJoyUpDown, $hDll) ;Right Joystick moved up
        _KeyUpDown(1048576, '{BROWSER_REFRESH down}', $iRightJoyDownDown, $hDll) ;Right Joystick moved down
    EndIf
    If _IsPressed360(32, $hDll) Then _Hibernate(32, 5000, $hDll) ; Back button pressed
    Sleep(25)
WEnd

Func _Hibernate($iKey360, $iTime = 5000, $vDll = "xinput9_1_0.dll")
    Local $iTimer = TimerInit()
    While 1
        If Not _IsPressed360($iKey360, $vDll) Then Return 0
        If TimerDiff($iTimer) > $iTime Then ExitLoop
    WEnd
    If _IsPressed360($iKey360, $vDll) Then
        Shutdown(64)
        Return 0
    EndIf
EndFunc   ;==>_Hibernate

Func _MouseUpDown($iKey360, $sPressKey, ByRef $iVar, $vDll = "xinput9_1_0.dll")
    If _IsPressed360($iKey360, $vDll) And $iVar = 0 Then
        MouseDown($sPressKey)
        $iVar = 1
    ElseIf Not _IsPressed360($iKey360, $vDll) And $iVar = 1 Then
        MouseUp($sPressKey)
        $iVar = 0
    EndIf
EndFunc   ;==>_MouseUpDown

Func _KeyUpDown($iKey360, $sPressKey, ByRef $iVar, $vDll = "xinput9_1_0.dll")
    If _IsPressed360($iKey360, $vDll) And $iVar = 0 Then
        Send($sPressKey)
        $iVar = 1
    ElseIf Not _IsPressed360($iKey360, $vDll) And $iVar = 1 Then
        Send(StringRegExpReplace($sPressKey, '(\ down\})', ' up}'))
        $iVar = 0
    EndIf
EndFunc   ;==>_KeyUpDown

Func _MouseMove()
    Local $iX = MouseGetPos(0)
    Local $iY = MouseGetPos(1)
    If _IsPressed360(131072, $hDll) Then $iX += (@extended / 1000)
    If _IsPressed360(262144, $hDll) Then $iY -= (@extended / 1000)
    MouseMove($iX, $iY)
EndFunc   ;==>_MouseMove
Func _Exit()
    DllClose($hDll)
    Exit
EndFunc   ;==>_Exit
Edited by Djarlo

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...