struct Termisu::Event::Key

Overview

Keyboard input event.

Contains the key pressed and any modifier keys that were held.

Example:

event = termisu.poll_event
if event.is_a?(Termisu::Event::Key)
  if event.ctrl_c?
    puts "Ctrl+C pressed, exiting..."
  elsif event.key.escape?
    puts "Escape pressed"
  end
end

Defined in:

termisu/event/key.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(key : Input::Key, modifiers : Input::Modifier = Input::Modifier::None) #

[View source]

Instance Method Detail

def alt? : Bool #

Returns true if Alt modifier was held.


[View source]
def char : Char | Nil #

Returns the character for this key, if printable.


[View source]
def ctrl? : Bool #

Returns true if Ctrl modifier was held.


[View source]
def ctrl_c? : Bool #

Returns true if this is Ctrl+C.


[View source]
def ctrl_d? : Bool #

Returns true if this is Ctrl+D.


[View source]
def ctrl_q? : Bool #

Returns true if this is Ctrl+Q.


[View source]
def ctrl_z? : Bool #

Returns true if this is Ctrl+Z.


[View source]
def key : Input::Key #

The key that was pressed.


[View source]
def meta? : Bool #

Returns true if Meta modifier was held.


[View source]
def modifiers : Input::Modifier #

Modifier keys held during the keypress.


[View source]
def shift? : Bool #

Returns true if Shift modifier was held.


[View source]