AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

XInput - Xbox 360 Controller API
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Sun Dec 21, 2008 1:28 pm    Post subject: XInput - Xbox 360 Controller API Reply with quote

XInput
XInput.ahk wraps a few key functions of XInput, a.k.a. the Microsoft Common Controller API. It provides the following capabilities not otherwise accessible to scripts:
  • The official drivers report to Windows one axis for both analog triggers, making it impossible to detect when both triggers are pulled at once. XInput allows one to retrieve the state of each analog trigger individually.
  • Set level of controller vibration - left and right motor speeds.
Future versions may provide additional functionality:
  • Detect input on attached messenger kits (mini keyboards which can be attached to a controller).
  • Retrieve battery levels of wireless controllers.
  • Access the audio input/output of a given controller's headset.

Required: xinput1_3.dll
    This seems to be the current version of XInput, included in recent DirectX run-times.
Optional: Compliant JSON deserialized A/IO parser
    Simplifies parsing "structures" returned by XInput_GetState and XInput_GetCapabilities. (Required for the example script.)
XInput.ahk
Covered by Lexikos' default copyright license.

Example: Control the vibration motors using the analog triggers of each controller.
Code:
XInput_Init()
Loop {
    Loop, 4 {
        if XInput_GetState(A_Index-1, State)=0 {
            LT := json(State,"bLeftTrigger")
            RT := json(State,"bRightTrigger")
            XInput_SetState(A_Index-1, LT*257, RT*257)
        }
    }
    Sleep, 100
}


Last edited by Lexikos on Tue Dec 30, 2008 12:30 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Frankie



Joined: 02 Nov 2008
Posts: 828

PostPosted: Wed Dec 24, 2008 7:51 pm    Post subject: Reply with quote

Im getting a wireless adapter for the XBox 360 controller sometime soon. Is there any reason it won't work with wireless?
_________________
Click here to join #AHK channel in IRC for general chat and quick help.
Back to top
View user's profile Send private message AIM Address
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Thu Dec 25, 2008 9:55 am    Post subject: Reply with quote

I originally tested the script with one wireless controller. After your post, I also connected a wired controller - the script worked correctly with both controllers connected. It's easy to identify the index of a controller as it directly relates to the lit quadrant on the guide button.
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Fri May 29, 2009 3:24 pm    Post subject: Reply with quote

hi, is there anybody still working on it? would love to have the abbility to connect a xbox 360 controller wth my pc and use the chatpad and output sound to headset
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Fri May 29, 2009 3:49 pm    Post subject: Reply with quote

I doubt it. I don't own a chatpad.
Back to top
View user's profile Send private message Visit poster's website
mtgtopdeck



Joined: 25 Mar 2009
Posts: 17

PostPosted: Fri May 29, 2009 6:26 pm    Post subject: Reply with quote

There is a community of xbox users that might find this very useful.
If you get the time could you post about this script on the forums at xim360.com?
thank you
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Sat May 30, 2009 5:23 am    Post subject: Reply with quote

I'm not familiar with that community, where or what to post. Perhaps you'd better do it?
Back to top
View user's profile Send private message Visit poster's website
TheLeO



Joined: 11 Jun 2005
Posts: 203
Location: England ish

PostPosted: Fri Jun 19, 2009 4:10 pm    Post subject: Reply with quote

Thank you so much for this, I've been trying to figure out how to make xinput work with ahk for quite a while.

BTW, is there anyway to determine if the user presses the big "X" button on the controller? (or taps it)//

thanks again, I'll be testing it ..
_________________
And i say: where there is a problem , there is a solution.(well some where that is.)
::
I Have Spoken
::
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Fri Jun 19, 2009 7:07 pm    Post subject: Reply with quote

I'm not aware of any way.
Back to top
View user's profile Send private message Visit poster's website
constell
Guest





PostPosted: Mon Oct 12, 2009 2:56 am    Post subject: Reply with quote

For some reason, this doesn't work for me. Running the xinput.ahk file with the dll in the same directory. It just shows the tray icon for a split second then quits with no error message. What's up?
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Mon Oct 12, 2009 7:38 am    Post subject: Reply with quote

XInput.ahk doesn't do anything on its own; it's a library of functions for use in other scripts such as the example in my first post.
Back to top
View user's profile Send private message Visit poster's website
constell
Guest





PostPosted: Mon Oct 12, 2009 8:05 am    Post subject: Reply with quote

Ah, thanks for that. Sorry for bumping a pretty old post. Anyway, my original intention was to somehow find a way to overcome the current limitation of the 360 driver to detect when both triggers are pressed at once.

Looks like it isn't actually a limitation considering Xinput can actually detect when both triggers are pressed. There's a game that I wanna play that has moves where you have to press both triggers at once. I can download a 3rd party driver, but that would affect games that detect Xinput devices (GRiD, GTA4) and I prefer to still have that.

What's the simplest way I can do that? I'm thinking of maybe scripting something like joy2key, where it maps the controller input to the keyboard, hopefully being able to detect both triggers pressed at once. Then passing that onto the game. Problem is, I don't know anything about AutoHotKey scripting. I can learn, though. Anyway, is there an easier way you can think of other than this?
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Mon Oct 12, 2009 8:49 am    Post subject: Reply with quote

That limitation is the main reason I wrote XInput.ahk. If the game supports mixing keyboard and game controller input, you may use this to remap just the triggers:
Code:
; ~ Config:

; Minimum to be considered "pressed", between 1 (0.39%) and 255 (100%).
Threshold = 64

; Keys to bind to triggers.
LT_Key = [
RT_Key = ]

; ~

LastRT := LastLT := 0
XInput_Init()
Loop {
    Loop, 4 {
        if XInput_GetState(A_Index-1, State)=0 {
            LT := json(State,"bLeftTrigger") >= Threshold
            RT := json(State,"bRightTrigger") >= Threshold
            if (LT != LastLT) {
                Send % "{" . LT_Key . (LT ? " Down}" : " Up}")
                LastLT := LT
            }
            if (RT != LastRT) {
                Send % "{" . RT_Key . (RT ? " Down}" : " Up}")
                LastRT := RT
            }
        }
    }
    Sleep, 100
}

If you need to remap other buttons/axes, the methods outlined here may be sufficient.
Back to top
View user's profile Send private message Visit poster's website
Matze
Guest





PostPosted: Mon Oct 12, 2009 12:41 pm    Post subject: Reply with quote

I play NBA 2K for PC with xbox 360 Wireless contoller. The isomotion on the game is executed if the two triggers are pressed simultaneously, which because of the one axis doesnt do nothing actually.
Well I sense this could be a solution for it, but tried to run the script after I installe AutoHotkey but nothing changes.

Is there something I need to do in order to make it work, change something in the script, add some values or..? I'm just regular PC user and haven't been working with these kind of stuff till now.

PS. I have the xinput1_3.dll, I've searched for it.

Thank u guys, ur help would be very appreciated.
Back to top
Lexikos



Joined: 17 Oct 2006
Posts: 4457
Location: Qld, Australia

PostPosted: Mon Oct 12, 2009 1:00 pm    Post subject: Reply with quote

Obviously, the script can't make the game recognize the two triggers as separate axes. It only translates the triggers into two keys: [ and ]. You need to either bind these keys to something in your game, or change the keys in the script (simply replace the [ and/or ] characters).
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group