AutoHotkey Community

It is currently May 27th, 2012, 12:24 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: June 22nd, 2011, 1:58 am 
Offline

Joined: May 15th, 2011, 6:50 pm
Posts: 16
JPFlash wrote:
I too ran into the message:
"Failed to initialize XInput: function not found."

I poured through the code myself and couldn't find anything wrong with it. After doing some heavy research I came across something and the answer hit me like a ton of bricks.

In the XInput_Init() function, GetProcAddress is used to get the function addresses of the XInputGetState, XInputSetState, and XInputGetCapabilities from the xinput1_3.dll. Unfortunately, GetProcAddress doesn't work in unicode.

For those of us that have installed the most recent version of AutoHotKey and/or are running on 64-bit systems are using the unicode version of AutoHotKey.

I installed the 32-bit ANSI version of AHK and XInput ran flawlessly. Looks like we 64-bit users need to find an alternative method instead of GetProcAddress or just use the 32-bit version of AHK.



Alright, I've installed 32bit ansi and ran the script posted by the naked general and...

I got rid of the "Failed to initialize XInput: function not found." message but the tooltip still showed no value, than i realised that...

my controller was not plugged... :lol: :lol: :lol: :lol:

It's working now, thanks man...
you're my saviour


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Unicode solution found!
PostPosted: June 22nd, 2011, 2:17 am 
Not willing to give up on this, I kept doing research and found out that GetProcAddress is working fine, except that it is getting passed a unicode string instead of the expected ANSI string. As a result, it returns a NULL address and the error-checking reveals that the functions did not load.

DllCall() supports a few extra argument types such as AStr and WStr. AStr is an ANSI string type and WStr is a unicode string type. All that needs to be done is just adjust the argument type that gets passed in during DllCall() from "str" to "AStr" so that GetProcAddress is passed the ANSI string it needs.

Within XInput_Init():
Code:
_XInput_GetState        := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"str","XInputGetState")
_XInput_SetState        := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"str","XInputSetState")
_XInput_GetCapabilities := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"str","XInputGetCapabilities")

Becomes:
Code:
_XInput_GetState        := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"AStr","XInputGetState")
_XInput_SetState        := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"AStr","XInputSetState")
_XInput_GetCapabilities := DllCall("GetProcAddress" ,"uint",_XInput_hm ,"AStr","XInputGetCapabilities")

Now it works fine on the 64-bit unicode version of AHK!

Additionally, my research led me to find that LoadLibrary has a unicode version called LoadLibraryW. After making the argument changes it didn't seem to matter which version of LoadLibrary was used, they both worked fine. However, I wonder which is best to use with the 64-bit unicode version of AHK. Any thoughts on that?

Example:
Code:
_XInput_hm := DllCall("LoadLibrary" ,"str",dll)

-or-

_XInput_hm := DllCall("LoadLibraryW" ,"str",dll)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 22nd, 2011, 3:33 am 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
LoadLibraryW should allow you to pass a unicode string.

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 29th, 2011, 9:23 pm 
Offline

Joined: November 28th, 2011, 10:11 pm
Posts: 4
maybe somebody has a use for this, i stumbled upon it while searching for a tool to get deadzones in Richard Burns Rally ( and it worked )


-> third party open source drivers for the xbox controllers

http://translate.google.com/translate?s ... F~morii%2F

http://www.katch.ne.jp/~morii/


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 9th, 2012, 12:25 am 
i'm trying to get this to work with SetTimer, but i can only get this to work with a loop.

for example, i would like to have a set timer that is persistent:

SetTimer, checkRTrig, 20
SetTimer, checkLTrig, 20

and it would do the following:

checkRTrig:
if (r trigger is down)
send {key}
return

checkLTrig:
if (l trigger is down)
send {diff. key}
return

any help is definitely appreciated! thank you!


Report this post
Top
  
Reply with quote  
PostPosted: May 9th, 2012, 4:31 pm 
Offline
User avatar

Joined: March 26th, 2012, 9:17 am
Posts: 32
Location: Dallas TX
Here's a trigger test script I wrote a while back, I've commented where you would put the send keys for demonstration.
Notice the settimers at the top there, took some trial and error to get it right.
Hope it helps :D
Code:
XInput_Init()

Threshold = 64 ; for trigger deadzones
   
; I recomend the set to 1 here, works better than "ON" flag
SetTimer, TRIGGERWATCH, 1
SetTimer, GOOD_VIBRATIONS, 1

#include xinput.ahk ; the goods
;~ #include JSON.ahk ; Uncomment if JSON is not in your standard lib
return

Esc::
ExitApp ; GTFO
return

TRIGGERSTATE:
; Keys to bind to triggers.
LT_Key = Null
RT_Key = Null

LastRT := LastLT := 0
XInput_Init()
    Loop, 4 {
        if XInput_GetState(A_Index-1, State)=0 {
            LT := json(State,"bLeftTrigger")
            RT := json(State,"bRightTrigger")
            BT := json(State,"wButtons")
            ;~ XInput_SetState(A_Index-1, LT*257, RT*257) ; VIBRATE!
        }
   }
return

TRIGGERWATCH:
gosub TRIGGERSTATE ; redundantly redundant
if (LT > Threshold and RT > Threshold) ;Both triggers are held
vibewait := 10 ; this is where the send logic can be placed
if (LT <= Threshold and RT <= Threshold) ;No triggers are held
vibewait := 9 ; and here
if (LT > Threshold and RT <= Threshold) ;Left trigger is held
vibewait := 4 ; and here
if (LT <= Threshold and RT > Threshold) ;Right trigger is held
vibewait := 8 ; and here

Tooltip I'M AN ANOYING TOOLTIP! `n`nLTrigger-%LT%     RTrigger-%RT%`n  Button Info-%BT%`nvibewait-%vibewait%

return

GOOD_VIBRATIONS:
; these vibration routines were pulled from my WoW health rumble script http://www.autohotkey.com/community/viewtopic.php?t=75729

If vibewait < 9
{
      Loop, 4 {
         if XInput_GetState(A_Index-1, State)=0 { 
            XInput_SetState(A_Index-1, vibewait*4000, vibewait*8000) ;MAX 65535
            sleep 100
            XInput_SetState(A_Index-1, vibewait*8191, vibewait*16383) ;MAX 65535
            sleep 250
            XInput_SetState(A_Index-1, vibewait*8000, vibewait*4000) ;MAX 65535
            sleep 100
            XInput_SetState(A_Index-1, vibewait*16383, vibewait*8191) ;MAX 65535 big 16383 low 8191
            Sleep 250
            XInput_SetState(A_Index-1, vibewait*4000, vibewait*8000) ;MAX 65535
            sleep 100
            XInput_SetState(A_Index-1, vibewait*8191, vibewait*16383) ;MAX 65535
            sleep 250
            XInput_SetState(A_Index-1, 0, 0) ;MAX 65535
            sleep 2000/vibewait
                                       }
            }
}
If vibewait > 9
{
   ; you have died of dysentery
ISDEAD = YUP!
      Loop, 4 {
         if XInput_GetState(A_Index-1, State)=0 { 
            XInput_SetState(A_Index-1, vibewait*10, vibewait*500) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*500, vibewait*1000) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*1000, vibewait*4000) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*4000, vibewait*1000) ;MAX 65535 big 16383 low 8191
            Sleep 500
            XInput_SetState(A_Index-1, vibewait*1000, vibewait*500) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*500, vibewait*10) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, 0, 0) ;MAX 65535
            sleep 10000/vibewait
            XInput_SetState(A_Index-1, vibewait*500, vibewait*10) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*1000, vibewait*500) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*4000, vibewait*1000) ;MAX 65535 big 16383 low 8191
            sleep 500
            XInput_SetState(A_Index-1, vibewait*1000, vibewait*4000) ;MAX 65535
            Sleep 500
            XInput_SetState(A_Index-1, vibewait*500, vibewait*1000) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, vibewait*10, vibewait*500) ;MAX 65535
            sleep 500
            XInput_SetState(A_Index-1, 0, 0) ;MAX 65535
            sleep 10000/vibewait
                                       }
            }
return
}
else
{
      Loop, 4 {
         if XInput_GetState(A_Index-1, State)=0 { 
            XInput_SetState(A_Index-1, 0, 0) ;MAX 65535
                                       }
            }
}
return

_________________
My code is built and tested for: AutoHotkey_L
Tools:GISTOR Dropiler
Libs:RFN Achieve
Image
(ಠ_ಠ) (ಠڼʘ)


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 Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, Google Feedfetcher, SKAN and 5 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