AutoHotkey Community

It is currently May 26th, 2012, 12:50 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: December 21st, 2008, 2:28 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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 December 30th, 2008, 1:30 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 24th, 2008, 8:51 pm 
Offline
User avatar

Joined: November 2nd, 2008, 4:23 pm
Posts: 2906
Location: 127.0.0.1
Im getting a wireless adapter for the XBox 360 controller sometime soon. Is there any reason it won't work with wireless?

_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2008, 10:55 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2009, 4:24 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2009, 4:49 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I doubt it. I don't own a chatpad.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 29th, 2009, 7:26 pm 
Offline

Joined: March 25th, 2009, 5:15 pm
Posts: 17
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2009, 6:23 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I'm not familiar with that community, where or what to post. Perhaps you'd better do it?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 5:10 pm 
Offline

Joined: June 11th, 2005, 9:34 am
Posts: 264
Location: England ish
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 ..

_________________
::
I Have Spoken
::


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2009, 8:07 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
I'm not aware of any way.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 3:56 am 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 8:38 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 9:05 am 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 9:49 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 1:41 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: October 12th, 2009, 2:00 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7502
Location: Australia
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).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], DataLife and 15 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group