toSpec method
Converts this KeyEvent to a specification string.
This is the inverse of KeyEvent.fromString. Outputs generic modifier names in canonical order: ctrl+alt+shift+super+hyper+meta
A keystroke has one identity, so shift is folded into the character it
produces rather than kept as a separate modifier: Shift+A is 'A',
Shift+1 is '!' — never 'shift+a' or 'shift+1'. Named keys are the
exception: they keep shift explicit, so Shift+Tab is 'shift+tab'.
Folding a cased letter is always safe — 'a' becomes 'A' regardless
of layout. Folding a symbol is only safe when the parser actually knows
what shift produced (the terminal reported Kitty's alternate "shifted
key"). On a terminal that disambiguates escape codes but doesn't report
alternate keys, Shift+1 arrives as the base character '1' plus a
shift modifier with no way to know the produced symbol ('!' on a US
layout, something else elsewhere) — folding would guess, so the spec
keeps the explicit modifier and stays 'shift+1'.
Does not encode: eventType, baseLayoutKey, keyPad, capsLock, text. Use toBaseLayoutSpec for a projection onto the base (US) layout key.
Examples:
KeyEvent.fromString('backSpace').toSpec()→'backSpace'KeyEvent.fromString('ctrl+a').toSpec()→'ctrl+a'KeyEvent(KeyCode.named(KeyCodeName.leftCtrl)).toSpec()→'ctrl'
Implementation
String toSpec() => _buildSpec(code, modifiers, charIsProduced: code.shiftProduced);