Jump to content

Reading triggers from a controller seperately


Recommended Posts

Hey guys just wanted to see if anyone has a clue on how to do this.

Basically when I read the value of the 2 triggers on my controller it returns a value between 0 and 65534.

When idle the value is 32767.

With the left trigger down it decreases this value by 1-32767 (depending on how far the trigger is pressed)

With the right trigger down it increases this value by 1-32767 (depending on how far the trigger is pressed)

the problem is with both triggers down the value is the same as the idle so how can I possibly distinguish between the two of them?

What am I doing?

I'm in the middle of creating a new program to handle my gamepad because xpadder has too many problems and now wants to charge for it.

The program is pretty much complete just lacks a pretty GUI and the ability to handle these triggers.

The code I used for the base was from a user named Ejoc

here is the post

and here is the code

EDITED : Found his original code without the game thing in it!

#include <GUIConstants.au3>

Local $joy,$coor,$h,$s,$msg

$joy    = _JoyInit()

GUICreate("Joystick Test",300,300)
$h= GuiCtrlCreatelabel("",10,10,290,290)
GUISetState()

while 1
    $msg    = GUIGetMSG()
    $coor   = _GetJoy($joy,0)
    $s      = "Joystick(0):" & @CRLF & _
                "X: " & $coor[0] & @CRLF & _
                "Y: " & $coor[1] & @CRLF & _
                "Z: " & $coor[2] & @CRLF & _
                "R: " & $coor[3] & @CRLF & _
                "U: " & $coor[4] & @CRLF & _
                "V: " & $coor[5] & @CRLF & _
                "POV: " & $coor[6] & @CRLF & _
                "Buttons: " & $coor[7]
    GUICtrlSetData($h,$s,1)
    sleep(10)
    if $msg = $GUI_EVENT_CLOSE Then Exitloop
WEnd

_JoyClose($joy)

;======================================
;   _JoyInit()
;======================================
Func _JoyInit()
    Local $joy
    Global $JOYINFOEX_struct    = "dword[13]"

    $joy    = DllStructCreate($JOYINFOEX_struct)
    if @error Then Return 0
    DllStructSet($joy,1,DllStructSize($joy),1);dwSize = sizeof(struct)
    DllStructSet($joy,1,255,2)             ;dwFlags = GetAll
    return $joy
EndFunc

;======================================
;   _GetJoy($lpJoy,$iJoy)
;   $lpJoy  Return from _JoyInit()
;   $iJoy   Joystick # 0-15
;   Return  Array containing X-Pos, Y-Pos, Z-Pos, R-Pos, U-Pos, V-Pos,POV
;           Buttons down
;
;           *POV This is a digital game pad, not analog joystick
;           65535   = Not pressed
;           0       = U
;           4500    = UR
;           9000    = R
;           Goes around clockwise increasing 4500 for each position
;======================================
Func _GetJoy($lpJoy,$iJoy)
    Local $coor,$ret

    Dim $coor[8]
    DllCall("Winmm.dll","int","joyGetPosEx",_
            "int",$iJoy,_
            "ptr",DllStructPtr($lpJoy))

    if Not @error Then
        $coor[0]    = DllStructGet($lpJoy,1,3)
        $coor[1]    = DllStructGet($lpJoy,1,4)
        $coor[2]    = DllStructGet($lpJoy,1,5)
        $coor[3]    = DllStructGet($lpJoy,1,6)
        $coor[4]    = DllStructGet($lpJoy,1,7)
        $coor[5]    = DllStructGet($lpJoy,1,8)
        $coor[6]    = DllStructGet($lpJoy,1,11)
        $coor[7]    = DllStructGet($lpJoy,1,9)
    EndIf

    return $coor
EndFunc

;======================================
;   _JoyClose($lpJoy)
;   Free the memory allocated for the joystick struct
;======================================
Func _JoyClose($lpJoy)
    DllStructFree($lpJoy)
EndFunc

The important part of this code

Func _GetJoy($lpJoy,$iJoy)
    Local $coor,$ret
    Dim $coor[8]
    DllCall("Winmm.dll","int","joyGetPosEx",_
            "int",$iJoy,_
            "ptr",DllStructGetPtr($lpJoy))
    if Not @error Then
        $coor[0]    = DllStructGetData($lpJoy,1,3)
        $coor[1]    = DllStructGetData($lpJoy,1,4)
        $coor[2]    = DllStructGetData($lpJoy,1,5)
        $coor[3]    = DllStructGetData($lpJoy,1,6)
        $coor[4]    = DllStructGetData($lpJoy,1,7)
        $coor[5]    = DllStructGetData($lpJoy,1,8)
        $coor[6]    = DllStructGetData($lpJoy,1,11)
        $coor[7]    = DllStructGetData($lpJoy,1,9)
    EndIf
    return $coor
EndFunc

$coor[2] is the value for the triggers i spoke about above.

Any ideas? I wouldn't mind having to read them as simple buttons as I don't need the actual axis they control (Z axis I believe)

Thanks in advance!

Quick Edit: I have done a great deal of searching about this but have somehow failed... sorry If you find it very easily

Edited by LordNeo
Link to comment
Share on other sites

What changed since you made this statement: ?

More like what does this have to do with game automation at all?

This is about making my controller say button one press the X key on the keyboard

If that's game automation then I have no idea what game automation really is

Edited by LordNeo
Link to comment
Share on other sites

  • Developers

This has nothing to do with his original code other than the 2nd function

Did you read my post?

Nope, I am only glancing and am not interested in reading everything totally.

You should know you should avoid even mentioning anything related to games.......

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Nope, I am only glancing and am not interested in reading everything totally.

You should know you should avoid even mentioning anything related to games.......

Jos

I understand that but this isn't even related to games its more about control over my gamepad completely

Thank you for your concerns though

Link to comment
Share on other sites

Still looking for help on this!

If anyone could possibly provide a better method than using winmm.dll perhaps something like xinput/directinput that would help a lot! (even a link to a similar msdn library containing it as i cannot seem to find it)

I've looked up some documentation on winmm.dll but it isn't getting me anywhere.

The joyGetPosEx function for instance

http://msdn.microsoft.com/en-us/library/ms709354

and the page I got it from

http://msdn.microsoft.com/en-us/library/ms712636

Thanks all! :graduated:

Link to comment
Share on other sites

I still have not solved this problem.

A possible solution would be to use xinput.dll but I have no idea how to do that.

I've tried many things but I'm completely new when it comes to working with dlls.

If anyone can solve the math problem in the original post or help me with using xinput.dll it would be greatly appreciated :graduated:

Thanks again

edit: This link may be very useful to anyone who understands how to use it with autoit

http://msdn.microsoft.com/en-us/library/ee417005%28v=VS.85%29.aspx

Edited by LordNeo
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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