Jump to content
Joel_

Simulating Xbox One controller inputs to computer

Recommended Posts

Joel_

So, I've had this problem for a couple of days now, because I'm trying to automate a feature in my Xbox (currently running through streaming in my computer (Xbox App)) and I can't find any solution.

I have managed to run the program where you can read which button is pressed in a game controller from the following post: https://www.autoitscript.com/forum/topic/10953-joystick-udf/. But thats not what I actually need. I need to be able to press "B" (like if I was pressing the "B" button in my controller) in my computer without actually need to press it.

What I'm trying to do is detecting by PixelGetColor() if a certain menu was open on the Xbox, and if that's the case, virtually press the "B" button to close it, leaving the user unable to open that certain menu.

I would appreciate any solutions, because this will allow me to solve many problems I have with my Xbox automation script. :)

(If any doubts, I actually have a Xbox One controller connected to the computer)

Share this post


Link to post
Share on other sites
FrancescoDiMuro

Good morning @Joel_, and welcome to the AutoIt forum :)

I don't know if this kind of request could be taken as game automation. If so, you won't have any answer from here.

If it's not ( and I am not the one who can decide for that ), it is possible to do it, but yoi have to post the code you are working on, or a working reproducer of your script, in order to see what you did, and help you from what you did :)

 

Best Regards.


Click here to see my signature:

Spoiler

I will always thank you for the time you spent for me.
I'm here to ask, and from your response, I'd like to learn.
By my knowledge, I can help someone else, and "that someone" could help in turn another, and so on.

ALWAYS GOOD TO READ:

In case I am violating some pseudo Forum rule, or I am doing something wrong, I want let you know that I'm not doing this on purpose, and for this, I kindly ask you to send me a private message about the "bad content" I posted, in order to edit/remove it, and to not be warned wrongly.
Thanks in advance.

 

Share this post


Link to post
Share on other sites
Joel_

It's not for game automation purposes. See, I am renting (I don't know if thats the appropiate verb) my Xbox, like a personal bussiness, and I'm not able to control the kids from entering some menus I don't want like the "turning off Xbox" menu and "change session" menu. I just want to detect if any of those menus was open so I can send a "B" button and take them out of there.

Like I said, I was only able to run the code from the posted link: 

;____________________________________________________________________
;       Original program by Ejoc                                    ;
;       Improved by Adam1213 (autoit 3.2 compatiblity + improved labels         ;
;____________________________________________________________________

#include <GUIConstants.au3>

;_________________ SETUP_____________________________________
Local $joy,$coor,$h,$s,$msg

$joy    = _JoyInit()

dim $labels_text[8]=['X', 'Y', 'Z', 'R', 'U', 'V', 'POV', 'Buttons']
dim $labels_no=UBound($labels_text)
dim $labels[$labels_no]
dim $labels_value[$labels_no]
;__________ CONFIG ____________________________________________
;---------- Find the max length of the longest label --------------
$label_len=0
for $text in $labels_text
    $len=stringlen($text)
    if $len>$label_len then
        $label_len=$len
    endif
next
$label_len*=6
;_____________ GUI _______________________________________________
GUICreate('Joystick Test', 200, 200)
GUICtrlCreateLabel('Joystick', 40, 20, 100, 20)
    
for $i=0 to $labels_no-1
    GuiCtrlCreatelabel($labels_text[$i]&':', 10, 60+$i*12, $label_len, 12)
    $labels[$i]=GuiCtrlCreatelabel('', 10+$label_len, 60+$i*12, 70, 12)
    $labels_value[$i]=''
next
GUISetState()
;_____________________________________________________________________

while 1
    $coord=_GetJoy($joy,0)
    for $i=0 to UBound($coord)-1
        if $coord[$i]<>$labels_value[$i] then
            GUICtrlSetData($labels[$i], $coord[$i])
            $labels_value[$i]=$coord[$i]
        endif
    next
    sleep(10)
    $msg =GUIGetMSG()
    if $msg = $GUI_EVENT_CLOSE Then Exitloop
    
    ;*********************************************************
    ;Here I would like to detect If (Menu was open) Then  (With PixelGetColor(), that I have used)
    ;                                Send(A virtual "B" press)
    ;                            EndIf
    ;*********************************************************
    
WEnd

$lpJoy=0 ; Joyclose

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

    $joy=DllStructCreate($JOYINFOEX_struct)
    if @error Then Return 0
    DllStructSetData($joy, 1, DllStructGetSize($joy), 1);dwSize = sizeof(struct)
    DllStructSetData($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",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

 

I'm not very familiar with DLL's (if they end to be part of the solution), so I need help figuring out what code I need to be able to just send one "B" pulse.

 

Thanks in advance.

Share this post


Link to post
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

×