sendKeyEvent method
- LogicalKeyboardKey key, {
- String? platform,
- String? character,
- PhysicalKeyboardKey? physicalKey,
Simulates sending physical key down and up events.
This only simulates key events coming from a physical keyboard, not from a soft keyboard.
Specify platform
as one of the platforms allowed in
Platform.operatingSystem to make the event appear to be from
that type of system. If not specified, defaults to "web" on web, and the
operating system name based on defaultTargetPlatform everywhere else.
Specify the physicalKey
for the event to override what is included in
the simulated event. If not specified, it uses a default from the US
keyboard layout for the corresponding logical key
.
Specify the character
for the event to override what is included in the
simulated event. If not specified, it uses a default derived from the
logical key
.
Keys that are down when the test completes are cleared after each test.
This method sends both the key down and the key up events, to simulate a key press. To simulate individual down and/or up events, see sendKeyDownEvent and sendKeyUpEvent.
Returns true if the key down event was handled by the framework.
See also:
- sendKeyDownEvent to simulate only a key down event.
- sendKeyUpEvent to simulate only a key up event.
Implementation
Future<bool> sendKeyEvent(
LogicalKeyboardKey key, {
String? platform,
String? character,
PhysicalKeyboardKey? physicalKey
}) async {
final bool handled = await simulateKeyDownEvent(key, platform: platform, character: character, physicalKey: physicalKey);
// Internally wrapped in async guard.
await simulateKeyUpEvent(key, platform: platform, physicalKey: physicalKey);
return handled;
}