XInput: Allow several XInput devices to be used (not just the first one) + Added left/right trigger & right stick support
This commit is contained in:
parent
7becd0bff6
commit
3845c859a3
4 changed files with 103 additions and 21 deletions
|
@ -22,20 +22,33 @@ void GamePad::RefreshState()
|
|||
}
|
||||
}
|
||||
|
||||
bool GamePad::IsPressed(uint8_t gamepadPort, WORD button)
|
||||
bool GamePad::IsPressed(uint8_t gamepadPort, uint8_t button)
|
||||
{
|
||||
if(_gamePadStates[gamepadPort] != nullptr) {
|
||||
if(button == XINPUT_GAMEPAD_DPAD_LEFT && _gamePadStates[gamepadPort]->Gamepad.sThumbLX < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
_gamePadStates[gamepadPort]->Gamepad.wButtons |= button;
|
||||
} else if(button == XINPUT_GAMEPAD_DPAD_RIGHT && _gamePadStates[gamepadPort]->Gamepad.sThumbLX > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
_gamePadStates[gamepadPort]->Gamepad.wButtons |= button;
|
||||
} else if(button == XINPUT_GAMEPAD_DPAD_UP && _gamePadStates[gamepadPort]->Gamepad.sThumbLY > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
_gamePadStates[gamepadPort]->Gamepad.wButtons |= button;
|
||||
} else if(button == XINPUT_GAMEPAD_DPAD_DOWN && _gamePadStates[gamepadPort]->Gamepad.sThumbLY < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
_gamePadStates[gamepadPort]->Gamepad.wButtons |= button;
|
||||
XINPUT_GAMEPAD &gamepad = _gamePadStates[gamepadPort]->Gamepad;
|
||||
if(button <= 16) {
|
||||
WORD xinputButton = 1 << (button - 1);
|
||||
if(xinputButton == XINPUT_GAMEPAD_DPAD_LEFT && gamepad.sThumbLX < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
gamepad.wButtons |= xinputButton;
|
||||
} else if(xinputButton == XINPUT_GAMEPAD_DPAD_RIGHT && gamepad.sThumbLX > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
gamepad.wButtons |= xinputButton;
|
||||
} else if(xinputButton == XINPUT_GAMEPAD_DPAD_UP && gamepad.sThumbLY > XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
gamepad.wButtons |= xinputButton;
|
||||
} else if(xinputButton == XINPUT_GAMEPAD_DPAD_DOWN && gamepad.sThumbLY < -XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE) {
|
||||
gamepad.wButtons |= xinputButton;
|
||||
}
|
||||
|
||||
return (_gamePadStates[gamepadPort]->Gamepad.wButtons & xinputButton) != 0;
|
||||
} else {
|
||||
switch(button) {
|
||||
case 17: return gamepad.bLeftTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
|
||||
case 18: return gamepad.bRightTrigger > XINPUT_GAMEPAD_TRIGGER_THRESHOLD;
|
||||
case 19: return gamepad.sThumbRY > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
case 20: return gamepad.sThumbRY < -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
case 21: return gamepad.sThumbRX < -XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
case 22: return gamepad.sThumbRX > XINPUT_GAMEPAD_RIGHT_THUMB_DEADZONE;
|
||||
}
|
||||
}
|
||||
return (_gamePadStates[gamepadPort]->Gamepad.wButtons & button) != 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,5 +12,5 @@ class GamePad
|
|||
GamePad();
|
||||
|
||||
void RefreshState();
|
||||
bool IsPressed(uint8_t gamepadPort, WORD button);
|
||||
bool IsPressed(uint8_t gamepadPort, uint8_t button);
|
||||
};
|
||||
|
|
|
@ -22,7 +22,7 @@ bool WindowsKeyManager::IsKeyPressed(uint32_t key)
|
|||
//XInput key
|
||||
uint8_t gamepadPort = (key - 0xFFFF) / 0x100;
|
||||
uint8_t gamepadButton = (key - 0xFFFF) % 0x100;
|
||||
return _gamePad.IsPressed(gamepadPort, 1 << (gamepadButton - 1));
|
||||
return _gamePad.IsPressed(gamepadPort, gamepadButton);
|
||||
} else {
|
||||
return (GetAsyncKeyState(key) & 0x8000) == 0x8000;
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ uint32_t WindowsKeyManager::GetPressedKey()
|
|||
_gamePad.RefreshState();
|
||||
|
||||
for(int i = 0; i < XUSER_MAX_COUNT; i++) {
|
||||
for(int j = 1; j <= 16; j++) {
|
||||
if(_gamePad.IsPressed(i, 1 << (j - 1))) {
|
||||
for(int j = 1; j <= 22; j++) {
|
||||
if(_gamePad.IsPressed(i, j)) {
|
||||
return 0xFFFF + i * 0x100 + j;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,14 +213,83 @@ const KeyDefinition _keyDefinitions[] = {
|
|||
{ "", 0xFFFF + 0x04, "Pad1 Right" },
|
||||
{ "", 0xFFFF + 0x05, "Pad1 Start" },
|
||||
{ "", 0xFFFF + 0x06, "Pad1 Back" },
|
||||
{ "", 0xFFFF + 0x07, "Pad1 Left Thumb" },
|
||||
{ "", 0xFFFF + 0x08, "Pad1 Right Thumb" },
|
||||
{ "", 0xFFFF + 0x09, "Pad1 Left Bumper" },
|
||||
{ "", 0xFFFF + 0x0A, "Pad1 Right Bumper" },
|
||||
{ "", 0xFFFF + 0x07, "Pad1 L3" },
|
||||
{ "", 0xFFFF + 0x08, "Pad1 R3" },
|
||||
{ "", 0xFFFF + 0x09, "Pad1 L1" },
|
||||
{ "", 0xFFFF + 0x0A, "Pad1 R1" },
|
||||
{ "", 0xFFFF + 0x0D, "Pad1 A" },
|
||||
{ "", 0xFFFF + 0x0E, "Pad1 B" },
|
||||
{ "", 0xFFFF + 0x0F, "Pad1 X" },
|
||||
{ "", 0xFFFF + 0x10, "Pad1 Y" }
|
||||
{ "", 0xFFFF + 0x10, "Pad1 Y" },
|
||||
{ "", 0xFFFF + 0x11, "Pad1 L2" },
|
||||
{ "", 0xFFFF + 0x12, "Pad1 R2" },
|
||||
{ "", 0xFFFF + 0x13, "Pad1 RT Up" },
|
||||
{ "", 0xFFFF + 0x14, "Pad1 RT Down" },
|
||||
{ "", 0xFFFF + 0x15, "Pad1 RT Left" },
|
||||
{ "", 0xFFFF + 0x16, "Pad1 RT Right" },
|
||||
|
||||
{ "", 0xFFFF + 0x101, "Pad2 Up" },
|
||||
{ "", 0xFFFF + 0x102, "Pad2 Down" },
|
||||
{ "", 0xFFFF + 0x103, "Pad2 Left" },
|
||||
{ "", 0xFFFF + 0x104, "Pad2 Right" },
|
||||
{ "", 0xFFFF + 0x105, "Pad2 Start" },
|
||||
{ "", 0xFFFF + 0x106, "Pad2 Back" },
|
||||
{ "", 0xFFFF + 0x107, "Pad2 Left Thumb" },
|
||||
{ "", 0xFFFF + 0x108, "Pad2 Right Thumb" },
|
||||
{ "", 0xFFFF + 0x109, "Pad2 Left Bumper" },
|
||||
{ "", 0xFFFF + 0x10A, "Pad2 Right Bumper" },
|
||||
{ "", 0xFFFF + 0x10D, "Pad2 A" },
|
||||
{ "", 0xFFFF + 0x10E, "Pad2 B" },
|
||||
{ "", 0xFFFF + 0x10F, "Pad2 X" },
|
||||
{ "", 0xFFFF + 0x110, "Pad2 Y" },
|
||||
{ "", 0xFFFF + 0x111, "Pad2 L2" },
|
||||
{ "", 0xFFFF + 0x112, "Pad2 R2" },
|
||||
{ "", 0xFFFF + 0x113, "Pad2 RT Up" },
|
||||
{ "", 0xFFFF + 0x114, "Pad2 RT Down" },
|
||||
{ "", 0xFFFF + 0x115, "Pad2 RT Left" },
|
||||
{ "", 0xFFFF + 0x116, "Pad2 RT Right" },
|
||||
|
||||
{ "", 0xFFFF + 0x201, "Pad3 Up" },
|
||||
{ "", 0xFFFF + 0x202, "Pad3 Down" },
|
||||
{ "", 0xFFFF + 0x203, "Pad3 Left" },
|
||||
{ "", 0xFFFF + 0x204, "Pad3 Right" },
|
||||
{ "", 0xFFFF + 0x205, "Pad3 Start" },
|
||||
{ "", 0xFFFF + 0x206, "Pad3 Back" },
|
||||
{ "", 0xFFFF + 0x207, "Pad3 Left Thumb" },
|
||||
{ "", 0xFFFF + 0x208, "Pad3 Right Thumb" },
|
||||
{ "", 0xFFFF + 0x209, "Pad3 Left Bumper" },
|
||||
{ "", 0xFFFF + 0x20A, "Pad3 Right Bumper" },
|
||||
{ "", 0xFFFF + 0x20D, "Pad3 A" },
|
||||
{ "", 0xFFFF + 0x20E, "Pad3 B" },
|
||||
{ "", 0xFFFF + 0x20F, "Pad3 X" },
|
||||
{ "", 0xFFFF + 0x210, "Pad3 Y" },
|
||||
{ "", 0xFFFF + 0x211, "Pad3 L2" },
|
||||
{ "", 0xFFFF + 0x212, "Pad3 R2" },
|
||||
{ "", 0xFFFF + 0x213, "Pad3 RT Up" },
|
||||
{ "", 0xFFFF + 0x214, "Pad3 RT Down" },
|
||||
{ "", 0xFFFF + 0x215, "Pad3 RT Left" },
|
||||
{ "", 0xFFFF + 0x216, "Pad3 RT Right" },
|
||||
|
||||
{ "", 0xFFFF + 0x301, "Pad4 Up" },
|
||||
{ "", 0xFFFF + 0x302, "Pad4 Down" },
|
||||
{ "", 0xFFFF + 0x303, "Pad4 Left" },
|
||||
{ "", 0xFFFF + 0x304, "Pad4 Right" },
|
||||
{ "", 0xFFFF + 0x305, "Pad4 Start" },
|
||||
{ "", 0xFFFF + 0x306, "Pad4 Back" },
|
||||
{ "", 0xFFFF + 0x307, "Pad4 Left Thumb" },
|
||||
{ "", 0xFFFF + 0x308, "Pad4 Right Thumb" },
|
||||
{ "", 0xFFFF + 0x309, "Pad4 Left Bumper" },
|
||||
{ "", 0xFFFF + 0x30A, "Pad4 Right Bumper" },
|
||||
{ "", 0xFFFF + 0x30D, "Pad4 A" },
|
||||
{ "", 0xFFFF + 0x30E, "Pad4 B" },
|
||||
{ "", 0xFFFF + 0x30F, "Pad4 X" },
|
||||
{ "", 0xFFFF + 0x310, "Pad4 Y" },
|
||||
{ "", 0xFFFF + 0x311, "Pad4 L2" },
|
||||
{ "", 0xFFFF + 0x312, "Pad4 R2" },
|
||||
{ "", 0xFFFF + 0x313, "Pad4 RT Up" },
|
||||
{ "", 0xFFFF + 0x314, "Pad4 RT Down" },
|
||||
{ "", 0xFFFF + 0x315, "Pad4 RT Left" },
|
||||
{ "", 0xFFFF + 0x316, "Pad4 RT Right" }
|
||||
};
|
||||
|
||||
class WindowsKeyManager : public IKeyManager
|
||||
|
|
Loading…
Add table
Reference in a new issue