Skip to content

Commit 3950120

Browse files
committed
Add triggers to 'getButton' function
These can already be treated as digital by the 'set' function, so we should be able to treat them as digital with the 'get' function as well. Any input greater than 0 is considered 'pressed' - other thresholds can be done by the user with the analog function.
1 parent 8c943ad commit 3950120

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/XInput.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,9 +370,15 @@ void XInputController::setAutoSend(boolean a) {
370370
}
371371

372372
boolean XInputController::getButton(uint8_t button) const {
373-
const XInputMap_Button * buttonData = getButtonFromEnum((XInputControl) button);
374-
if (buttonData == nullptr) return 0; // Not a button
375-
return tx[buttonData->index] & buttonData->mask;
373+
const XInputMap_Button* buttonData = getButtonFromEnum((XInputControl) button);
374+
if (buttonData != nullptr) {
375+
return tx[buttonData->index] & buttonData->mask;
376+
}
377+
const XInputMap_Trigger* triggerData = getTriggerFromEnum((XInputControl) button);
378+
if (triggerData != nullptr) {
379+
return getTrigger((XInputControl) button) != 0 ? 1 : 0;
380+
}
381+
return 0; // Not a button or a trigger
376382
}
377383

378384
boolean XInputController::getDpad(XInputControl dpad) const {

0 commit comments

Comments
 (0)