@@ -5540,9 +5540,9 @@ let lastInputDevice = 'mouse';
55405540/** Screen-pixel mouse movement per frame that counts as "using the mouse"
55415541 * (so sub-pixel hand jitter doesn't steal focus from the keyboard/gamepad).
55425542 * @type {number}
5543- * @default 2
5543+ * @default
55445544 * @memberof Input */
5545- let inputMouseMoveThreshold = 2 ;
5545+ let inputMouseMoveThreshold = 6 ;
55465546
55475547/** Prevents input continuing to the default browser handling (true by default)
55485548 * @type {boolean}
@@ -6071,34 +6071,41 @@ function inputUpdate()
60716071 // update gamepads if enabled
60726072 gamepadsUpdate();
60736073
6074- // ── most-recently-used input device (sticky while everything is idle) ──
6075- // gamepad: any stick past a .2 magnitude (.04 = .2²), or any of the 17
6076- // standard-mapping buttons (0..16) held
6077- let gamepadActive = false;
6078- for (let s = gamepadStickCount(); s-- && !gamepadActive;)
6079- gamepadActive = gamepadStick(s).lengthSquared() > .04;
6080- for (let b = 17; b-- && !gamepadActive;)
6081- gamepadActive = gamepadIsDown(b);
6082-
6083- // mouse: any button held, or moved past the jitter threshold (screen px)
6084- const mouseActive = mouseIsDown(0) || mouseIsDown(1) || mouseIsDown(2) ||
6085- mouseDeltaScreen.length() > inputMouseMoveThreshold;
6086-
6087- // keyboard: any non-mouse key currently down. device 0 holds both keyboard
6088- // codes (e.g. 'KeyA') and mouse buttons (numeric 0..4); skip the numeric
6089- // ones with isNaN(+k) so keyboard detection is exact
6090- let keyboardActive = false;
6091- for (const k in inputData[0])
6092- if (isNaN(+k) && (inputData[0][k] & 1)) { keyboardActive = true; break; }
6093-
6094- // priority on a same-frame tie: gamepad > mouse > keyboard
6095- if (gamepadActive) lastInputDevice = 'gamepad';
6096- else if (mouseActive) lastInputDevice = 'mouse';
6097- else if (keyboardActive) lastInputDevice = 'keyboard';
6098- // else keep the previous value — the whole point (idle never reverts)
6099-
6100- // keep the legacy flag as an accurate derived view (single source of truth)
6101- isUsingGamepad = lastInputDevice === 'gamepad';
6074+ // update most recently used input device
6075+ updateLastInputDevice();
6076+
6077+ function updateLastInputDevice()
6078+ {
6079+ // mouse: any button held or moved
6080+ const mouseActive = mouseIsDown(0) || mouseIsDown(1) || mouseIsDown(2) || mouseDeltaScreen.length() > inputMouseMoveThreshold;
6081+
6082+ // gamepad: any button held or stick moved
6083+ let gamepadActive = false;
6084+ for (let s = gamepadStickCount(); s-- && !gamepadActive;)
6085+ gamepadActive = gamepadStick(s).lengthSquared() > .04;
6086+ for (let b = 17; b-- && !gamepadActive;)
6087+ gamepadActive = gamepadIsDown(b);
6088+
6089+ // keyboard: any non-mouse key down
6090+ let keyboardActive = false;
6091+ for (const k in inputData[0])
6092+ if (isNaN(+k) && (inputData[0][k] & 1))
6093+ {
6094+ keyboardActive = true;
6095+ break;
6096+ }
6097+
6098+ // update the last input
6099+ if (gamepadActive)
6100+ lastInputDevice = 'gamepad';
6101+ else if (mouseActive)
6102+ lastInputDevice = 'mouse';
6103+ else if (keyboardActive)
6104+ lastInputDevice = 'keyboard';
6105+
6106+ // set flag if gamepad is last device
6107+ isUsingGamepad = lastInputDevice === 'gamepad';
6108+ }
61026109
61036110 // gamepads are updated by engine every frame automatically
61046111 function gamepadsUpdate()
0 commit comments