Turn off XBOX 360 Controller

Started by
5 comments, last by DaFox 12 years, 5 months ago
[font="Arial, Helvetica, sans-serif"]Hi Devs,[/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"]Im trying to turn off my XBOX 360 Controller which is connected using the wireless module from Microsoft.[/font]
[font="Arial, Helvetica, sans-serif"]I can easily let it vibrate using this C# code:[/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"]
using SlimDX.XInput;

Controller controller = new Controller(UserIndex.One);
Vibration vibration = new Vibration {LeftMotorSpeed = 0000, RightMotorSpeed = 0000};
controller.SetVibration(vibration);

[/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"]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?[/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"]Thanks in advance![/font]
[font="Arial, Helvetica, sans-serif"] [/font]
[font="Arial, Helvetica, sans-serif"]MemphiZ[/font]
Advertisement
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.

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.


Well there must be a way. Because the Author of this little Script http://djpety.nt-hosting.hu/XboxExt/ 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?
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
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:
$nController = 1
$XInputDLL = DllOpen("xinput1_3.dll")
DllCall($XInputDLL, "long", 103, "int", $nController)


C++:

#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;
}


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.
I would expect that there's a possibility that this will break on future revisions of XInput.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

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.

This topic is closed to new replies.

Advertisement