Guide API
Skip to main content

Key

Enum Key 

Source
pub enum Key {
Show 16 variants Char(char), F(u8), Enter, Esc, Backspace, Tab, Up, Down, Left, Right, Home, End, PageUp, PageDown, Insert, Delete,
}
Expand description

A logical, modifier-free key — the base of a KeyEvent.

Keyboard keys and key-down events.

A keystroke is modeled the idiomatic, crossterm-shaped way: a closed Key enum of physical keys plus a separate KeyModifiers channel. There are deliberately no modifier-combined variants: Ctrl+C is Key::Char('c') plus ctrl, Shift+Tab is Key::Tab plus shift, and Alt+F3 is Key::F(3) plus alt. A KeyEvent pairs a key with the modifiers active when it was pressed.

There is no “no key” value: the absence of a keystroke is the absence of a key event.

Only the 16 base keys appear here; modifier combinations are expressed by pairing a Key with a KeyModifiers in a KeyEvent:

  • Ctrl+C → Key::Char('c') + modifiers.ctrl = true
  • Shift+Tab → Key::Tab + modifiers.shift = true
  • Alt+F3 → Key::F(3) + modifiers.alt = true

This replaces the ~150 kb* combined key+modifier constants from tkeys.h; each constant was a specific bitwise combination of a scan code and a modifier mask. Here the two dimensions are orthogonal and independently matchable.

There is no BackTab variant. Shift+Tab is Key::Tab with shift set. Raw hardware scan codes are not preserved (they are DOS-era platform data with no cross-platform meaning).

§Turbo Vision heritage

Ports the kb* key-code family, the TKey class (tkeys.h / tkey.cpp), and KeyDownEvent (system.h). TKey’s canonical form already decomposes each keystroke into a base code plus a modifier mask (Ctrl+A is 'A' with the ctrl-shift mask; Shift+Tab is the Tab code with the shift mask); tvision-rs keeps that decomposition as the Key enum and a separate KeyModifiers (deviations D4 and D5).

Ports the kb* key-code family (tkeys.h) and the TKey canonical form (tkeys.h / tkey.cpp); the 1992 guide’s charCode: Char (low byte) maps to Key::Char(char) carrying the full Unicode character. Deviations D4 and D5.

Variants§

§

Char(char)

A printable character: letters, digits, symbols, and space.

Holds the base character case-as-typed; case modification and Ctrl/Alt semantics live in the accompanying KeyModifiers. The 1992 guide’s charCode: Char (low byte of keyCode: Word) maps here, extended to full Unicode.

§

F(u8)

A function key, F(1)..=F(12).

§

Enter

The Enter/Return key.

§

Esc

The Escape key.

§

Backspace

The Backspace key.

§

Tab

The Tab key. Note there is no BackTab variant: Shift+Tab is Tab + the shift modifier.

§

Up

The Up arrow key.

§

Down

The Down arrow key.

§

Left

The Left arrow key.

§

Right

The Right arrow key.

§

Home

The Home key.

§

End

The End key.

§

PageUp

The Page Up key.

§

PageDown

The Page Down key.

§

Insert

The Insert key.

§

Delete

The Delete key.

Trait Implementations§

Source§

impl Clone for Key

Source§

fn clone(&self) -> Key

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Key

Source§

impl Debug for Key

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Key

Source§

impl From<Key> for KeyEvent

The common no-modifier case: KeyEvent::from(Key::Enter) yields an event with all modifiers cleared.

Source§

fn from(key: Key) -> Self

Converts to this type from the input type.
Source§

impl Hash for Key

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Key

Source§

fn eq(&self, other: &Key) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Key

Auto Trait Implementations§

§

impl Freeze for Key

§

impl RefUnwindSafe for Key

§

impl Send for Key

§

impl Sync for Key

§

impl Unpin for Key

§

impl UnsafeUnpin for Key

§

impl UnwindSafe for Key

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CustomValue for T
where T: Any + Debug,

Source§

fn as_any_rc(self: Rc<T>) -> Rc<dyn Any>

Upcast Rc<Self> to Rc<dyn Any> so FieldValue::as_custom / FieldValue::value_as can downcast.
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.