Zuzu-Typ / XInput-Python

Simple access to the DirectX input API for Python
zlib License
28 stars 5 forks source link

Add support for xbox guide button #8

Open danielbibit opened 2 years ago

danielbibit commented 2 years ago

This PR adds the xbox guide button support.

I'm calling the xinput function by ordinal as described in this post: http://reverseengineerlog.blogspot.com/2016/06/xinputs-hidden-functions.html

Also, this xinput wrapper for AutoHotKey use this to be able to get the guide button: https://www.autohotkey.com/boards/viewtopic.php?t=29659#:~:text=XInput.,triggers%20are%20pulled%20at%20once.

(_XInput_GetState        := DllCall("GetProcAddress" ,"ptr",_XInput_hm ,"ptr",100 ,"ptr"))
|| (_XInput_GetState        := DllCall("GetProcAddress" ,"ptr",_XInput_hm ,"astr","XInputGetState" ,"ptr"))

I took the liberty to update the example code as well. Hope this PR is helpfull.

Zuzu-Typ commented 2 years ago

Hey there (:

thank you very much for your work and the detailed information you gave alongside with it ^^

I've tried it out, but it doesn't seem to work on my end. I presume you tested it and it did work for you, right? I've tested it with an XBox 360 controller as well as a regular XBox One controller, but didn't have any luck unfortunately.

May I ask, which Windows version are you using?

danielbibit commented 2 years ago

Here's my windows info

Edition Windows 10 Pro
Version 21H2
Installed on    ‎01/‎06/‎2021
OS build    19044.1586
Experience  Windows Feature Experience Pack 120.2212.4170.0

My controller is a xbox one series x connected via the microsoft dongle.

I just tested using 'XInput1_4.dll' and 'XInput1_3.dll'.

Yeah, it's working fine, I'm testing using this script:

if __name__ == "__main__":

    from XInput import *
    from time import sleep

    while True:
        print(get_button_values(get_state(0))['GUIDE'])
        sleep(0.5)

The console log prints true when pressed.

Can you use your guide button on steam to open big picture, or use it in another application ?

danielbibit commented 2 years ago

The dolphin emulator achive this the same way:

// Ordinal 100 is the same as XInputGetState, except it doesn't dummy out the guide
// button info. Try loading it and fall back if needed.
PXInputGetState = (XInputGetState_t)::GetProcAddress(hXInput, (LPCSTR)100);

https://github.com/dolphin-emu/dolphin/blob/master/Source/Core/InputCommon/ControllerInterface/XInput/XInput.cpp