struct CrystGLFW::Key

Overview

A key represents a physical key on the keyboard.

Defined in:

crystglfw/key.cr

Instance Method Summary

Instance Method Detail

def code : Int32 #

[View source]
def is?(*labels : Symbol) : Bool #

Returns true if the key is referenced by the given label. False otherwise.

window.on_key do |key_event|
  key = key_event.key
  if key.is? :key_a
    puts "the 'a' key was pressed."
  end
end

Also accepts multiple labels and returns true if the key's label matches any of them.

window.on_key do |key_event|
  key = key_event.key
  if key.is? :key_a, :key_b, :key_c
    puts "A, B, C!"
  elsif key.is? :key_1, :key_2, :key_3
    puts "Easy as 1, 2, 3!"
  else
    puts "Uh...do, re, mi?"
  end
end

This method accepts the following arguments:

  • labels, any number of labels against which the key will be checked.

[View source]
def name #

Returns the key's name, if the key is printable. Otherwise raises an exception.

if key.printable?
  puts key.name # prints the key's name
end


NOTE: This method must be called from within a `CrystGLFW#run` block definition.

[View source]
def printable? : Bool #

Returns true if the key is considered printable. False otherwise.

window.on_key do |key_event|
  key = key_event.key
  puts key.name if key.printable?
end

[View source]
def scancode : Int32 #

[View source]