Reading deviceId for RawKeyEventDataAndroid event (#42235)
This PR adds a new property on RawKeyEventDataAndroid to hold the deviceId from which that event was generated. The deviceId is been sent from the engine on the changes from this PR: flutter/engine#12958 With this, we will be able to identify from where the event came from, adding the ability to support local multiplayer games, with multiple gamepads.
This commit is contained in:
committed by
Greg Spencer
parent
560873af92
commit
12b7b08da5
@@ -260,6 +260,7 @@ abstract class RawKeyEvent extends Diagnosticable {
|
||||
eventSource: message['source'] ?? 0,
|
||||
vendorId: message['vendorId'] ?? 0,
|
||||
productId: message['productId'] ?? 0,
|
||||
deviceId: message['deviceId'] ?? 0,
|
||||
);
|
||||
break;
|
||||
case 'fuchsia':
|
||||
|
||||
@@ -36,6 +36,7 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
|
||||
this.eventSource = 0,
|
||||
this.vendorId = 0,
|
||||
this.productId = 0,
|
||||
this.deviceId = 0,
|
||||
}) : assert(flags != null),
|
||||
assert(codePoint != null),
|
||||
assert(keyCode != null),
|
||||
@@ -127,6 +128,12 @@ class RawKeyEventDataAndroid extends RawKeyEventData {
|
||||
/// for the numerical values of the `productId`.
|
||||
final int productId;
|
||||
|
||||
|
||||
/// The ID of the device that produced the event.
|
||||
///
|
||||
/// See https://developer.android.com/reference/android/view/InputDevice.html#getId()
|
||||
final int deviceId;
|
||||
|
||||
// The source code that indicates that an event came from a joystick.
|
||||
// from https://developer.android.com/reference/android/view/InputDevice.html#SOURCE_JOYSTICK
|
||||
static const int _sourceJoystick = 0x01000010;
|
||||
|
||||
@@ -40,6 +40,7 @@ void main() {
|
||||
'scanCode': 0x20,
|
||||
'metaState': modifier,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = event.data;
|
||||
for (ModifierKey key in ModifierKey.values) {
|
||||
@@ -75,6 +76,7 @@ void main() {
|
||||
'scanCode': 0x20,
|
||||
'metaState': modifier | RawKeyEventDataAndroid.modifierFunction,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = event.data;
|
||||
for (ModifierKey key in ModifierKey.values) {
|
||||
@@ -112,6 +114,7 @@ void main() {
|
||||
'scanCode': 30,
|
||||
'metaState': 0x0,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = keyAEvent.data;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.keyA));
|
||||
@@ -128,6 +131,7 @@ void main() {
|
||||
'scanCode': 1,
|
||||
'metaState': 0x0,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = escapeKeyEvent.data;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.escape));
|
||||
@@ -145,6 +149,7 @@ void main() {
|
||||
'scanCode': 42,
|
||||
'metaState': RawKeyEventDataAndroid.modifierLeftShift,
|
||||
'source': 0x101, // Keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = shiftLeftKeyEvent.data;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.shiftLeft));
|
||||
@@ -162,6 +167,7 @@ void main() {
|
||||
'scanCode': 0,
|
||||
'metaState': 0,
|
||||
'source': 0x1000010, // Joystick source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = joystickDpadDown.data;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.arrowDown));
|
||||
@@ -196,12 +202,29 @@ void main() {
|
||||
'scanCode': 317, // Left side thumb joystick center click button.
|
||||
'metaState': 0,
|
||||
'source': 0x501, // Gamepad and keyboard source.
|
||||
'deviceId': 1,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = joystickDpadCenter.data;
|
||||
expect(data.physicalKey, equals(PhysicalKeyboardKey.gameButtonThumbLeft));
|
||||
expect(data.logicalKey, equals(LogicalKeyboardKey.select));
|
||||
expect(data.keyLabel, isNull);
|
||||
});
|
||||
test('Device id is read from message', () {
|
||||
final RawKeyEvent joystickDpadCenter = RawKeyEvent.fromMessage(const <String, dynamic>{
|
||||
'type': 'keydown',
|
||||
'keymap': 'android',
|
||||
'keyCode': 23, // DPAD_CENTER code.
|
||||
'plainCodePoint': 0,
|
||||
'codePoint': 0,
|
||||
'character': null,
|
||||
'scanCode': 317, // Left side thumb joystick center click button.
|
||||
'metaState': 0,
|
||||
'source': 0x501, // Gamepad and keyboard source.
|
||||
'deviceId': 10,
|
||||
});
|
||||
final RawKeyEventDataAndroid data = joystickDpadCenter.data;
|
||||
expect(data.deviceId, equals(10));
|
||||
});
|
||||
});
|
||||
group('RawKeyEventDataFuchsia', () {
|
||||
const Map<int, _ModifierCheck> modifierTests = <int, _ModifierCheck>{
|
||||
|
||||
Reference in New Issue
Block a user