typeKey method

void typeKey(
  1. String key, {
  2. bool keyDown = true,
  3. bool keyUp = true,
})

Adds to sequence: ('keydown', 'keypress', 'keyup') events on key.

key must be a single-length String of the character sent.

keyDown and keyUp determines whether those events should be sent. 'keypress' is automatically sent if keyDown is true.

Throws error if the key sent violates the state of whether shift is being held down or not. For example: if 'keydown' on shift is already in sequence without sending a 'keyup' and key of '1' is sent, throws an error. Error is also thrown in the opposite case.

Implementation

void typeKey(String key, {bool keyDown = true, bool keyUp = true}) {
  // Throw if not exactly of length 1.
  if (key.length != 1) {
    throw ArgumentError("'typeKey' requires a key of exactly length 1");
  }

  // Check for consistency of [key] and status of [_shiftMod].
  if (_shiftMod && !isShiftValue(key)) {
    throw ArgumentError(
        "Cannot type a non-shift value '$key' while modded with shift. "
        "Execute at least 'typeSpecialKey(PageLoaderSpecialKey.shift)' with "
        "'keyUp' enabled before typing in '$key'.");
  } else if (!_shiftMod && isShiftValue(key)) {
    throw ArgumentError(
        "Cannot type a shift value '$key' before modded with shift. "
        "Execute at least 'typeSpecialKey(PageLoaderSpecialKey.shift)' with "
        "'keyDown' enabled before typing in '$key'.");
  }

  if (keyDown) {
    _addEvent(null, key, KeyboardEventType.keyDown);
    _addEvent(null, key, KeyboardEventType.keyPress);
  }
  if (keyUp) {
    _addEvent(null, key, KeyboardEventType.keyUp);
  }
  _addUniqueEvent(null, key);
}