struct TermBuf::Key

Overview

One key press.

A key is a value: it says which key, which modifiers, and for an ordinary character which character. What the terminal sent to say so is on the Events::Key that carries it, since two terminals can send different bytes for the same key and an application should not have to care.

Modifiers are only as good as the terminal's encoding. Ctrl with a letter arrives as one control byte, so Ctrl+I and Tab are the same key press and nothing downstream can separate them. Terminals implementing the kitty keyboard protocol can, which is why that protocol exists.

Defined in:

termbuf/input/key.cr

Constructors

Instance Method Summary

Constructor Detail

def self.character(char : Char, modifiers : Modifiers = Modifiers::None) : Key #

An ordinary character key.


[View source]
def self.named(name : Name, modifiers : Modifiers = Modifiers::None) : Key #

A named key.


[View source]
def self.new(name : Name, char : Char = '\0', modifiers : Modifiers = Modifiers::None) #

[View source]

Instance Method Detail

def alt? : Bool #

Whether alt was held.


[View source]
def char : Char #

The character pressed, for a Character key. '\0' for anything else.


[View source]
def character? : Bool #

Whether this is an ordinary character rather than a named key.


[View source]
def ctrl? : Bool #

Whether control was held.


[View source]
def is?(char : Char) : Bool #

Whether this is char with no modifiers but shift, which is what asking "did they type a q" means.


[View source]
def is?(name : Name) : Bool #

Whether this is the named key, whatever was held down with it.


[View source]
def modifiers : Modifiers #

What was held down with it.


[View source]
def name : Name #

Which key, with Name::Character meaning the one in #char.


[View source]
def shift? : Bool #

Whether shift was held.


[View source]
def super? : Bool #

Whether the windows, command, or meta key was held.


[View source]
def to_s(io : IO) : Nil #

A form suited to a key binding table: Ctrl+C, Alt+Up, Shift+F5.


[View source]