pressKey method

  1. @override
Future<void> pressKey(
  1. KeyName key, {
  2. int count = 1,
  3. Set<KeyModifier> modifiers = const {},
})
override

Presses key count times, each press bracketed by modifiers. Throws UnsupportedBackendAction when the backend has no keyboard.

Implementation

@override
Future<void> pressKey(KeyName key, {int count = 1, Set<KeyModifier> modifiers = const {}}) async {
  final code = key.androidKeyCode;
  if (await _viaServer({'cmd': 'key', 'code': code, 'meta': androidMetaState(modifiers), 'count': count})) return;
  if (modifiers.isEmpty) {
    await _shell(['input', 'keyevent', ...List.filled(count, '$code')]);
    return;
  }
  final combo = [
    ...modifiers.map((m) => '${m.androidKeyCode}'),
    '$code',
  ];
  for (var i = 0; i < count; i++) {
    await _shell(['input', 'keycombination', ...combo]);
  }
}