struct CrystGLFW::Key
- CrystGLFW::Key
- Struct
- Value
- Object
Overview
A key represents a physical key on the keyboard.
Defined in:
crystglfw/key.crInstance Method Summary
- #code : Int32
-
#is?(*labels : Symbol) : Bool
Returns true if the key is referenced by the given label.
-
#name
Returns the key's name, if the key is printable.
-
#printable? : Bool
Returns true if the key is considered printable.
- #scancode : Int32
Instance Method Detail
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.
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.
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