pub fn keycode_to_char(code: KeyCode) -> Option<char>Expand description
Converts a KeyCode into its corresponding character, if applicable.
§Parameters
code: TheKeyCodeto convert.
§Returns
Some(char): If theKeyCoderepresents a printable character.None: If theKeyCodeis not a character (e.g., arrow keys, function keys).
§Example
fn main() -> FtuiResult<()> {
// Capture user keyboard input as a KeyCode.
// If reading fails, terminate with an error.
let key_code = key()?;
// If a key was pressed, attempt to convert it to a character.
match key_code {
Some(code) => match keycode_to_char(code) {
// Print the character if it's a printable key.
Some(c) => println!("Key pressed: {}", c),
None => println!("Unprintable KeyCode"),
},
// No key was pressed, exit the function.
None => return,
}
Ok(())
}