/
deviceInputSystem.ts
603 lines (509 loc) · 25.8 KB
/
deviceInputSystem.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
import { Engine } from '../Engines/engine';
import { Tools } from '../Misc/tools';
import { IDisposable } from '../scene';
import { Nullable } from '../types';
import { DeviceType, PointerInput } from './InputDevices/deviceEnums';
/** @hidden */
declare const _native: any;
/**
* This class will take all inputs from Keyboard, Pointer, and
* any Gamepads and provide a polling system that all devices
* will use. This class assumes that there will only be one
* pointer device and one keyboard.
*/
export class DeviceInputSystem implements IDisposable {
/**
* Returns onDeviceConnected callback property
* @returns Callback with function to execute when a device is connected
*/
public get onDeviceConnected() { return this._onDeviceConnected; }
/**
* Sets callback function when a device is connected and executes against all connected devices
* @param callback Function to execute when a device is connected
*/
public set onDeviceConnected(callback) {
this._onDeviceConnected = callback;
// Iterate through each active device and rerun new callback
for (let deviceType = 0; deviceType < this._inputs.length; deviceType++) {
if (this._inputs[deviceType]) {
for (let deviceSlot = 0; deviceSlot < this._inputs[deviceType].length; deviceSlot++) {
if (this._inputs[deviceType][deviceSlot]) {
this._onDeviceConnected(deviceType, deviceSlot);
}
}
}
}
}
/**
* Callback to be triggered when a device is disconnected
*/
public onDeviceDisconnected: (deviceType: DeviceType, deviceSlot: number) => void = () => { };
/**
* Callback to be triggered when event driven input is updated
*/
public onInputChanged: (deviceType: DeviceType, deviceSlot: number, inputIndex: number, previousState: Nullable<number>, currentState: Nullable<number>, eventData?: any) => void;
// Private Members
private _inputs: Array<Array<Array<number>>> = [];
private _gamepads: Array<DeviceType>;
private _keyboardActive: boolean = false;
private _pointerActive: boolean = false;
private _elementToAttachTo: HTMLElement;
private _keyboardDownEvent = (evt: any) => { };
private _keyboardUpEvent = (evt: any) => { };
private _keyboardBlurEvent = (evt: any) => { };
private _pointerMoveEvent = (evt: any) => { };
private _pointerDownEvent = (evt: any) => { };
private _pointerUpEvent = (evt: any) => { };
private _pointerWheelEvent = (evt: any) => { };
private _pointerBlurEvent = (evt: any) => { };
private _wheelEventName: string;
private _gamepadConnectedEvent = (evt: any) => { };
private _gamepadDisconnectedEvent = (evt: any) => { };
private _onDeviceConnected: (deviceType: DeviceType, deviceSlot: number) => void = () => { };
private static _MAX_KEYCODES: number = 255;
private static _MAX_POINTER_INPUTS: number = Object.keys(PointerInput).length / 2;
private _eventPrefix: string;
private constructor(engine: Engine) {
const inputElement = engine.getInputElement();
this._eventPrefix = Tools.GetPointerPrefix(engine);
if (inputElement) {
this._elementToAttachTo = inputElement;
// Set tab index for the inputElement to the engine's canvasTabIndex, if and only if the element's tab index is -1
this._elementToAttachTo.tabIndex = (this._elementToAttachTo.tabIndex !== -1) ? this._elementToAttachTo.tabIndex : engine.canvasTabIndex;
this._handleKeyActions();
this._handlePointerActions();
this._handleGamepadActions();
// Check for devices that are already connected but aren't registered. Currently, only checks for gamepads and mouse
this._checkForConnectedDevices();
}
}
/**
* Creates a new DeviceInputSystem instance
* @param engine Engine to pull input element from
* @returns The new instance
*/
public static Create(engine: Engine): DeviceInputSystem {
// If running in Babylon Native, then defer to the native input system, which has the same public contract
if (typeof _native !== 'undefined' && _native.DeviceInputSystem) {
return new _native.DeviceInputSystem(engine);
}
return new DeviceInputSystem(engine);
}
// Public functions
/**
* Checks for current device input value, given an id and input index
* @param deviceName Id of connected device
* @param inputIndex Index of device input
* @returns Current value of input
*/
/**
* Checks for current device input value, given an id and input index. Throws exception if requested device not initialized.
* @param deviceType Enum specifiying device type
* @param deviceSlot "Slot" or index that device is referenced in
* @param inputIndex Id of input to be checked
* @returns Current value of input
*/
public pollInput(deviceType: DeviceType, deviceSlot: number, inputIndex: number): number {
const device = this._inputs[deviceType][deviceSlot];
if (!device) {
throw `Unable to find device ${DeviceType[deviceType]}`;
}
this._updateDevice(deviceType, deviceSlot, inputIndex);
if (device[inputIndex] === undefined) {
throw `Unable to find input ${inputIndex} for device ${DeviceType[deviceType]} in slot ${deviceSlot}`;
}
// When the mouse wheel is moved, only clear the value if that input is polled for
if (deviceType === DeviceType.Mouse && (inputIndex >= PointerInput.MouseWheelX && inputIndex <= PointerInput.MouseWheelZ)) {
const currentValue = device[inputIndex];
device[inputIndex] = 0;
return currentValue;
}
return device[inputIndex];
}
/**
* Check for a specific device in the DeviceInputSystem
* @param deviceType Type of device to check for
* @returns bool with status of device's existence
*/
public isDeviceAvailable(deviceType: DeviceType) {
return (this._inputs[deviceType] !== undefined);
}
/**
* Dispose of all the eventlisteners
*/
public dispose() {
// Blur Events
this._elementToAttachTo.removeEventListener("blur", this._keyboardBlurEvent);
this._elementToAttachTo.removeEventListener("blur", this._pointerBlurEvent);
// Keyboard Events
if (this._keyboardActive) {
this._elementToAttachTo.removeEventListener("keydown", this._keyboardDownEvent);
this._elementToAttachTo.removeEventListener("keyup", this._keyboardUpEvent);
}
// Pointer Events
if (this._pointerActive) {
this._elementToAttachTo.removeEventListener(this._eventPrefix + "move", this._pointerMoveEvent);
this._elementToAttachTo.removeEventListener(this._eventPrefix + "down", this._pointerDownEvent);
this._elementToAttachTo.removeEventListener(this._eventPrefix + "up", this._pointerUpEvent);
this._elementToAttachTo.removeEventListener(this._wheelEventName, this._pointerWheelEvent);
}
// Gamepad Events
window.removeEventListener("gamepadconnected", this._gamepadConnectedEvent);
window.removeEventListener("gamepaddisconnected", this._gamepadDisconnectedEvent);
}
/**
* Checks for existing connections to devices and register them, if necessary
* Currently handles gamepads and mouse
*/
private _checkForConnectedDevices() {
const gamepads = navigator.getGamepads();
for (const gamepad of gamepads) {
if (gamepad) {
this._addGamePad(gamepad);
}
}
// If the device in use has mouse capabilities, pre-register mouse
if (matchMedia('(pointer:fine)').matches) {
// This will provide a dummy value for the cursor position and is expected to be overriden when the first mouse event happens.
// There isn't any good way to get the current position outside of a pointer event so that's why this was done.
this._addPointerDevice(DeviceType.Mouse, 0, 0, 0);
}
}
// Private functions
/**
* Add a gamepad to the DeviceInputSystem
* @param gamepad A single DOM Gamepad object
*/
private _addGamePad(gamepad: any) {
const deviceType = this._getGamepadDeviceType(gamepad.id);
const deviceSlot = gamepad.index;
this._registerDevice(deviceType, deviceSlot, gamepad.buttons.length + gamepad.axes.length);
this._gamepads = this._gamepads || new Array<DeviceType>(gamepad.index + 1);
this._gamepads[deviceSlot] = deviceType;
}
/**
* Add pointer device to DeviceInputSystem
* @param deviceType Type of Pointer to add
* @param deviceSlot Pointer ID (0 for mouse, pointerId for Touch)
* @param currentX Current X at point of adding
* @param currentY Current Y at point of adding
*/
private _addPointerDevice(deviceType: DeviceType, deviceSlot: number, currentX: number, currentY: number) {
this._pointerActive = true;
this._registerDevice(deviceType, deviceSlot, DeviceInputSystem._MAX_POINTER_INPUTS);
const pointer = this._inputs[deviceType][deviceSlot]; /* initialize our pointer position immediately after registration */
pointer[0] = currentX;
pointer[1] = currentY;
}
/**
* Add device and inputs to device array
* @param deviceType Enum specifiying device type
* @param deviceSlot "Slot" or index that device is referenced in
* @param numberOfInputs Number of input entries to create for given device
*/
private _registerDevice(deviceType: DeviceType, deviceSlot: number, numberOfInputs: number) {
if (!this._inputs[deviceType]) {
this._inputs[deviceType] = [];
}
if (!this._inputs[deviceType][deviceSlot]) {
const device = new Array<number>(numberOfInputs);
for (let i = 0; i < numberOfInputs; i++) {
device[i] = 0; /* set device input as unpressed */
}
this._inputs[deviceType][deviceSlot] = device;
this.onDeviceConnected(deviceType, deviceSlot);
}
}
/**
* Given a specific device name, remove that device from the device map
* @param deviceType Enum specifiying device type
* @param deviceSlot "Slot" or index that device is referenced in
*/
private _unregisterDevice(deviceType: DeviceType, deviceSlot: number) {
if (this._inputs[deviceType][deviceSlot]) {
delete this._inputs[deviceType][deviceSlot];
this.onDeviceDisconnected(deviceType, deviceSlot);
}
}
/**
* Handle all actions that come from keyboard interaction
*/
private _handleKeyActions() {
this._keyboardDownEvent = ((evt) => {
if (!this._keyboardActive) {
this._keyboardActive = true;
this._registerDevice(DeviceType.Keyboard, 0, DeviceInputSystem._MAX_KEYCODES);
}
const kbKey = this._inputs[DeviceType.Keyboard][0];
if (kbKey) {
kbKey[evt.keyCode] = 1;
if (this.onInputChanged) {
this.onInputChanged(DeviceType.Keyboard, 0, evt.keyCode, 0, kbKey[evt.keyCode], evt);
}
}
});
this._keyboardUpEvent = ((evt) => {
if (!this._keyboardActive) {
this._keyboardActive = true;
this._registerDevice(DeviceType.Keyboard, 0, DeviceInputSystem._MAX_KEYCODES);
}
const kbKey = this._inputs[DeviceType.Keyboard][0];
if (kbKey) {
kbKey[evt.keyCode] = 0;
if (this.onInputChanged) {
this.onInputChanged(DeviceType.Keyboard, 0, evt.keyCode, 1, kbKey[evt.keyCode], evt);
}
}
});
this._keyboardBlurEvent = ((evt) => {
if (this._keyboardActive) {
const kbKey = this._inputs[DeviceType.Keyboard][0];
for (let i = 0; i < kbKey.length; i++) {
if (kbKey[i] !== 0) {
kbKey[i] = 0;
}
}
}
});
this._elementToAttachTo.addEventListener("keydown", this._keyboardDownEvent);
this._elementToAttachTo.addEventListener("keyup", this._keyboardUpEvent);
this._elementToAttachTo.addEventListener("blur", this._keyboardBlurEvent);
}
/**
* Handle all actions that come from pointer interaction
*/
private _handlePointerActions() {
this._pointerMoveEvent = ((evt) => {
const deviceType = (evt.pointerType === "mouse") ? DeviceType.Mouse : DeviceType.Touch;
const deviceSlot = (evt.pointerType === "mouse") ? 0 : evt.pointerId;
if (!this._inputs[deviceType]) {
this._inputs[deviceType] = [];
}
if (!this._inputs[deviceType][deviceSlot]) {
this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);
}
const pointer = this._inputs[deviceType][deviceSlot];
if (pointer) {
// Store previous values for event
const previousHorizontal = pointer[PointerInput.Horizontal];
const previousVertical = pointer[PointerInput.Vertical];
const previousDeltaHorizontal = pointer[PointerInput.DeltaHorizontal];
const previousDeltaVertical = pointer[PointerInput.DeltaVertical];
pointer[PointerInput.Horizontal] = evt.clientX;
pointer[PointerInput.Vertical] = evt.clientY;
pointer[PointerInput.DeltaHorizontal] = evt.movementX;
pointer[PointerInput.DeltaVertical] = evt.movementY;
if (this.onInputChanged) {
if (previousHorizontal !== evt.clientX) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Horizontal, previousHorizontal, pointer[PointerInput.Horizontal], evt);
}
if (previousVertical !== evt.clientY) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Vertical, previousVertical, pointer[PointerInput.Vertical], evt);
}
if (pointer[PointerInput.DeltaHorizontal] !== 0) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.DeltaHorizontal, previousDeltaHorizontal, pointer[PointerInput.DeltaHorizontal], evt);
}
if (pointer[PointerInput.DeltaVertical] !== 0) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.DeltaVertical, previousDeltaVertical, pointer[PointerInput.DeltaVertical], evt);
}
}
}
});
this._pointerDownEvent = ((evt) => {
const deviceType = (evt.pointerType === "mouse") ? DeviceType.Mouse : DeviceType.Touch;
const deviceSlot = (evt.pointerType === "mouse") ? 0 : evt.pointerId;
if (!this._inputs[deviceType]) {
this._inputs[deviceType] = [];
}
if (!this._inputs[deviceType][deviceSlot]) {
this._addPointerDevice(deviceType, deviceSlot, evt.clientX, evt.clientY);
}
const pointer = this._inputs[deviceType][deviceSlot];
if (pointer) {
const previousHorizontal = pointer[PointerInput.Horizontal];
const previousVertical = pointer[PointerInput.Vertical];
const previousButton = pointer[evt.button + 2];
pointer[PointerInput.Horizontal] = evt.clientX;
pointer[PointerInput.Vertical] = evt.clientY;
pointer[evt.button + 2] = 1;
if (this.onInputChanged) {
if (previousHorizontal !== evt.clientX) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Horizontal, previousHorizontal, pointer[PointerInput.Horizontal], evt);
}
if (previousVertical !== evt.clientY) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Vertical, previousVertical, pointer[PointerInput.Vertical], evt);
}
this.onInputChanged(deviceType, deviceSlot, evt.button + 2, previousButton, pointer[evt.button + 2], evt);
}
}
});
this._pointerUpEvent = ((evt) => {
const deviceType = (evt.pointerType === "mouse") ? DeviceType.Mouse : DeviceType.Touch;
const deviceSlot = (evt.pointerType === "mouse") ? 0 : evt.pointerId;
const pointer = this._inputs[deviceType]?.[deviceSlot];
if (pointer) {
const previousHorizontal = pointer[PointerInput.Horizontal];
const previousVertical = pointer[PointerInput.Vertical];
const previousButton = pointer[evt.button + 2];
pointer[PointerInput.Horizontal] = evt.clientX;
pointer[PointerInput.Vertical] = evt.clientY;
pointer[evt.button + 2] = 0;
if (this.onInputChanged) {
if (previousHorizontal !== evt.clientX) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Horizontal, previousHorizontal, pointer[PointerInput.Horizontal], evt);
}
if (previousVertical !== evt.clientY) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.Vertical, previousVertical, pointer[PointerInput.Vertical], evt);
}
this.onInputChanged(deviceType, deviceSlot, evt.button + 2, previousButton, pointer[evt.button + 2], evt);
}
// We don't want to unregister the mouse because we may miss input data when a mouse is moving after a click
if (evt.pointerType !== "mouse") {
this._unregisterDevice(deviceType, deviceSlot);
}
}
});
// Set Wheel Event Name, code originally from scene.inputManager
this._wheelEventName = "onwheel" in document.createElement("div") ? "wheel" : // Modern browsers support "wheel"
(<any>document).onmousewheel !== undefined ? "mousewheel" : // Webkit and IE support at least "mousewheel"
"DOMMouseScroll"; // let's assume that remaining browsers are older Firefox
// Code originally in scene.inputManager.ts
// Chrome reports warning in console if wheel listener doesn't set an explicit passive option.
// IE11 only supports captureEvent:boolean, not options:object, and it defaults to false.
// Feature detection technique copied from: https://github.com/github/eventlistener-polyfill (MIT license)
let passiveSupported = false;
const noop = function () { };
try {
const options: object = {
passive: {
get: function () {
passiveSupported = true;
}
}
};
this._elementToAttachTo.addEventListener("test", noop, options);
this._elementToAttachTo.removeEventListener("test", noop, options);
}
catch (e) {
/* */
}
this._pointerBlurEvent = ((evt) => {
// Handle mouse buttons
if (this.isDeviceAvailable(DeviceType.Mouse)) {
const pointer = this._inputs[DeviceType.Mouse][0];
for (let i = 0; i <= PointerInput.BrowserForward; i++) {
if (pointer[i + 2] === 1) {
pointer[i + 2] = 0;
if (this.onInputChanged) {
this.onInputChanged(DeviceType.Mouse, 0, i + 2, 1, pointer[i + 2]);
}
}
}
}
// Handle Active Touches
if (this.isDeviceAvailable(DeviceType.Touch)) {
const pointer = this._inputs[DeviceType.Touch];
for (let i = 0; i < pointer.length; i++) {
if (pointer[i]?.[PointerInput.LeftClick] === 1) {
pointer[i][PointerInput.LeftClick] = 0;
if (this.onInputChanged) {
this.onInputChanged(DeviceType.Touch, i, PointerInput.LeftClick, 1, pointer[i][PointerInput.LeftClick]);
}
this._unregisterDevice(DeviceType.Touch, i);
}
}
}
});
this._pointerWheelEvent = ((evt) => {
const deviceType = DeviceType.Mouse;
const deviceSlot = 0;
if (!this._inputs[deviceType]) {
this._inputs[deviceType] = [];
}
if (!this._inputs[deviceType][deviceSlot]) {
this._pointerActive = true;
this._registerDevice(deviceType, deviceSlot, DeviceInputSystem._MAX_POINTER_INPUTS);
}
const pointer = this._inputs[deviceType][deviceSlot];
if (pointer) {
// Store previous values for event
let previousWheelScrollX = pointer[PointerInput.MouseWheelX];
let previousWheelScrollY = pointer[PointerInput.MouseWheelY];
let previousWheelScrollZ = pointer[PointerInput.MouseWheelZ];
pointer[PointerInput.MouseWheelX] = evt.deltaX;
pointer[PointerInput.MouseWheelY] = evt.deltaY;
pointer[PointerInput.MouseWheelZ] = evt.deltaZ;
if (this.onInputChanged) {
if (evt.deltaX !== 0) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.MouseWheelX, previousWheelScrollX, pointer[PointerInput.MouseWheelX], evt);
}
if (evt.deltaY !== 0) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.MouseWheelY, previousWheelScrollY, pointer[PointerInput.MouseWheelY], evt);
}
if (evt.deltaZ !== 0) {
this.onInputChanged(deviceType, deviceSlot, PointerInput.MouseWheelZ, previousWheelScrollZ, pointer[PointerInput.MouseWheelZ], evt);
}
}
}
});
this._elementToAttachTo.addEventListener(this._eventPrefix + "move", this._pointerMoveEvent);
this._elementToAttachTo.addEventListener(this._eventPrefix + "down", this._pointerDownEvent);
this._elementToAttachTo.addEventListener(this._eventPrefix + "up", this._pointerUpEvent);
this._elementToAttachTo.addEventListener("blur", this._pointerBlurEvent);
this._elementToAttachTo.addEventListener(this._wheelEventName, this._pointerWheelEvent, passiveSupported ? { passive: false } : false);
}
/**
* Handle all actions that come from gamepad interaction
*/
private _handleGamepadActions() {
this._gamepadConnectedEvent = ((evt: any) => {
this._addGamePad(evt.gamepad);
});
this._gamepadDisconnectedEvent = ((evt: any) => {
if (this._gamepads) {
const deviceType = this._getGamepadDeviceType(evt.gamepad.id);
const deviceSlot = evt.gamepad.index;
this._unregisterDevice(deviceType, deviceSlot);
delete this._gamepads[deviceSlot];
}
});
window.addEventListener("gamepadconnected", this._gamepadConnectedEvent);
window.addEventListener("gamepaddisconnected", this._gamepadDisconnectedEvent);
}
/**
* Update all non-event based devices with each frame
* @param deviceType Enum specifiying device type
* @param deviceSlot "Slot" or index that device is referenced in
* @param inputIndex Id of input to be checked
*/
private _updateDevice(deviceType: DeviceType, deviceSlot: number, inputIndex: number) {
// Gamepads
const gp = navigator.getGamepads()[deviceSlot];
if (gp && deviceType === this._gamepads[deviceSlot]) {
const device = this._inputs[deviceType][deviceSlot];
if (inputIndex >= gp.buttons.length) {
device[inputIndex] = gp.axes[inputIndex - gp.buttons.length].valueOf();
}
else {
device[inputIndex] = gp.buttons[inputIndex].value;
}
}
}
/**
* Gets DeviceType from the device name
* @param deviceName Name of Device from DeviceInputSystem
* @returns DeviceType enum value
*/
private _getGamepadDeviceType(deviceName: string): DeviceType {
if (deviceName.indexOf("054c") !== -1 && deviceName.indexOf("0ce6") === -1) { // DualShock 4 Gamepad
return DeviceType.DualShock;
}
else if (deviceName.indexOf("Xbox One") !== -1 || deviceName.search("Xbox 360") !== -1 || deviceName.search("xinput") !== -1) { // Xbox Gamepad
return DeviceType.Xbox;
}
else if (deviceName.indexOf("057e") !== -1) { // Switch Gamepad
return DeviceType.Switch;
}
return DeviceType.Generic;
}
}