ensureKeyCase function
Implementation
Key ensureKeyCase(Key key, int cks) {
if (key.text.isEmpty) return key;
final hasShift = (cks & Win32ControlKeyState.shiftPressed) != 0;
final hasCaps = (cks & Win32ControlKeyState.capsLockOn) != 0;
final text = key.text;
if (text.isEmpty) return key;
final codeChar = String.fromCharCode(key.code);
if (hasShift || hasCaps) {
if (codeChar == codeChar.toLowerCase() &&
codeChar != codeChar.toUpperCase()) {
final shifted = codeChar.toUpperCase();
return Key(
code: key.code,
text: shifted,
mod: key.mod,
shiftedCode: uni.firstCodePoint(shifted),
baseCode: key.baseCode,
isRepeat: key.isRepeat,
);
}
} else {
if (codeChar == codeChar.toUpperCase() &&
codeChar != codeChar.toLowerCase()) {
final shifted = codeChar.toLowerCase();
return Key(
code: key.code,
text: shifted,
mod: key.mod,
shiftedCode: uni.firstCodePoint(shifted),
baseCode: key.baseCode,
isRepeat: key.isRepeat,
);
}
}
return key;
}