Sign in to follow this  
MemphiZ

Turn off XBOX 360 Controller

Recommended Posts

[font="Arial, Helvetica, sans-serif"][size="2"]Hi Devs,[/size][/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"][size="2"]Im trying to turn off my XBOX 360 Controller which is connected using the wireless module from Microsoft.[/size][/font]
[font="Arial, Helvetica, sans-serif"][size="2"]I can easily let it vibrate using this C# code:[/size][/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"][size="2"][code]
using SlimDX.XInput;

Controller controller = new Controller(UserIndex.One);
Vibration vibration = new Vibration {LeftMotorSpeed = 0000, RightMotorSpeed = 0000};
controller.SetVibration(vibration);
[/code]
[/size][/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"][size="2"]But I can't find any way to turn the controller off? Is that possible with XInput at all? If not, how can it be achieved?[/size][/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"][size="2"]Thanks in advance![/size][/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"][size="2"]MemphiZ[/size][/font]

Share this post


Link to post
Share on other sites
You can't programmatically turn of the controller, and with wireless controllers it's actually a pain to turn off when using PC since there is no consistent UI to turn off the controller as there is on Xbox. Generally I just quickly pop the battery out and back in which will shut it down. Elegant? No, but it saves my batteries from dying.

Share this post


Link to post
Share on other sites
[quote name='Nick Gravelyn' timestamp='1317923002' post='4869837']
You can't programmatically turn of the controller, and with wireless controllers it's actually a pain to turn off when using PC since there is no consistent UI to turn off the controller as there is on Xbox. Generally I just quickly pop the battery out and back in which will shut it down. Elegant? No, but it saves my batteries from dying.
[/quote]

Well there must be a way. Because the Author of this little Script [url="http://djpety.nt-hosting.hu/XboxExt/"]http://djpety.nt-hosting.hu/XboxExt/[/url] managed to do it with pure AutoIT. AutoIT is a scripting language that I know as well. The only thing I can imagine how he did it is a DLL Call/Invoke.

So?

Share this post


Link to post
Share on other sites
OK Solved it!

I was in contact with the Author of the mentioned AutoIT Script and he pointed me in the right direction.
To turn off the controller you must call a hidden function in the XInput1_3.dll by its ordinal (#103) as you dont have a function name exposed.

I've written a little Utility to do that for you. The SourceCode will be available soon when my Blog relaunches (www.X-ToolZ.com).
For everyone who can't wait here is the utility as a self installing/updating ClickOnce application: www.X-ToolZ.com/Downloads/X-360ControllerUtil

Hope this helps!

MemphiZ

Share this post


Link to post
Share on other sites
Glad that you got it working MemphiZ, this is basically the only thread that I could find that was discussing this issue.

Here is some sample code on how to do this.

AutoIT:
[code]$nController = 1
$XInputDLL = DllOpen("xinput1_3.dll")
DllCall($XInputDLL, "long", 103, "int", $nController)
[/code]

C++:
[code]
#include <windows.h>
#include <iostream>
#include "C:/Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Include\\XInput.h"

#pragma comment(lib, "C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Lib\\x64\\XInput.lib")

using namespace std;

typedef int (*FnOff)(int);

int wmain() {
HINSTANCE hXInputDLL = LoadLibraryA("XInput1_3.dll");
if (hXInputDLL == NULL) {
cout << "ERROR: Unable to load XInput1_3.dll!" << endl;
fgetc(stdin);
return 1;
}

unsigned result;
for (short i = 0; i < XUSER_MAX_COUNT; ++i) {
XINPUT_STATE state;
memset(&state, 0, sizeof(XINPUT_STATE));

result = XInputGetState(i, &state);

if(result == ERROR_SUCCESS) {
FnOff pOff;
pOff = FnOff(GetProcAddress(hXInputDLL, reinterpret_cast<char*>(103)));
pOff(i);
}
}

FreeLibrary(hXInputDLL);
return 0;
}[/code]

This C++ Code simply turns off all connected XInput devices.
You can probably safely skip the XInputGetState stuff though I have not tried calling XInput1_3.dll#103 on a device that is not connected. I'm sure it will be fine.

Share this post


Link to post
Share on other sites
Very possible. I would not use this in anything more than a controller manager. This is not something that any other type of application should be doing anyway.

Windows 7 ships with 4 versions of the XInput.dll though. I expect that Windows 8 will ship with the exact same XInput1_3.dll, and a new XInput1_4.dll.

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

Sign in to follow this