|
#pragma comment(lib, "Xinput.lib") |
|
|
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
|
|
#define WIN32_LEAN_AND_MEAN |
|
#include <windows.h> |
|
#include <Xinput.h> |
|
|
|
/* |
|
Ordinal 100: |
|
DWORD XInputGetStateEx(DWORD dwUserIndex, XINPUT_STATE *pState); |
|
|
|
Ordinal 101: |
|
DWORD XInputWaitForGuideButton(DWORD dwUserIndex, DWORD dwFlag, unKnown *pUnKnown); |
|
|
|
Ordinal 102: |
|
DWORD XInputCancelGuideButtonWait(DWORD dwUserIndex); |
|
|
|
Ordinal 103: |
|
DWORD XInputPowerOffController(DWORD dwUserIndex); |
|
*/ |
|
|
|
#define XINPUT_GAMEPAD_GUIDE 0x0400 |
|
|
|
typedef DWORD (WINAPI *XInputGetStateExProc)(DWORD dwUserIndex, XINPUT_STATE *pState); |
|
|
|
int main() |
|
{ |
|
HMODULE xinput_lib = LoadLibrary("xinput1_3.dll"); |
|
|
|
if(xinput_lib == NULL) |
|
{ |
|
printf("Could not load xinput1_3.dll. Trying xinput1_4.dll...\n"); |
|
|
|
xinput_lib = LoadLibrary("xinput1_4.dll"); |
|
|
|
if(xinput_lib == NULL) |
|
{ |
|
printf("Could not load xinput1_4.dll\n"); |
|
return 1; |
|
} |
|
} |
|
|
|
XInputGetStateExProc XInputGetStateEx; |
|
int XInputGetStateExOrdinal = 100; |
|
XInputGetStateEx = (XInputGetStateExProc) GetProcAddress(xinput_lib, (LPCTSTR) XInputGetStateExOrdinal); |
|
|
|
if(XInputGetStateEx == NULL) |
|
{ |
|
printf("Could not find XInputGetStateEx in xinput9_1_0.dll\n"); |
|
return 1; |
|
} |
|
|
|
XINPUT_STATE state; |
|
ZeroMemory(&state, sizeof(XINPUT_STATE)); |
|
|
|
DWORD active_controller = -1; |
|
for (DWORD i = 0; i < XUSER_MAX_COUNT; ++i) |
|
{ |
|
XINPUT_STATE state; |
|
ZeroMemory(&state, sizeof(XINPUT_STATE)); |
|
|
|
if (XInputGetState(i, &state) == ERROR_SUCCESS) |
|
{ |
|
printf("Controller %u found\n", i); |
|
|
|
if(active_controller == -1) |
|
{ |
|
printf("Controller %u is boss.\n"); |
|
active_controller = i; |
|
} |
|
} |
|
} |
|
|
|
if(active_controller == -1) |
|
{ |
|
printf("No controllers found. Aborting.\n"); |
|
return 1; |
|
} |
|
|
|
bool running = true; |
|
|
|
while(running) |
|
{ |
|
XInputGetStateEx(active_controller, &state); |
|
|
|
bool A_button_pressed = ((state.Gamepad.wButtons & XINPUT_GAMEPAD_GUIDE) != 0); |
|
|
|
if(A_button_pressed) |
|
{ |
|
printf("BUTTON\n"); |
|
} |
|
|
|
Sleep(10); |
|
} |
|
|
|
return 0; |
|
} |
A way to detect if the GUIDE button (the middle xbox logo) on the xbox controller was pressed. This works even when a game is running, which means you can intercept it during a game for your own purposes.