Class: Tea::Kbd::Down

Inherits:
Event
  • Object
show all
Defined in:
lib/tea/m_event_keyboard.rb

Overview

Event generated when a key is pressed down.

key

Physical key that was pressed, as a symbol (see key reference).

mods

Hash of the active key modifiers. Values are true or false, and the keys can be: :L_SHIFT, :R_SHIFT, :L_CTRL, :R_CTRL, :L_ALT, :R_ALT, :NUM_LOCK, :CAPS_LOCK, :ALT_GR. Also, :SHIFT, :CTRL and :ALT are provided for convenience, and Tea key constants with the same names can be used instead.

char

String character generated by that key and those modifiers. With Ruby >= 1.9, the encoding of this character is UTF-8, otherwise it varies with the running environment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Event

each_key

Constructor Details

#initialize(sdl_event) ⇒ Down

Returns a new instance of Down.



198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/tea/m_event_keyboard.rb', line 198

def initialize(sdl_event)
  @key = sdl_keysym_to_key(sdl_event.sym)
  @mods = sdl_keymod_to_mods(sdl_event.mod)

  if sdl_event.unicode != 0
    unicode_field = "%c"
    # Ruby 1.9 uses UTF-8 Unicode encoding.  Otherwise, who knows how
    # Unicode code points are interpreted?
    unicode_field = unicode_field.encode('utf-8') if RUBY_1_9
    @char = unicode_field % sdl_event.unicode
  else
    @char = ''
  end
end

Instance Attribute Details

#charObject (readonly)

Returns the value of attribute char.



197
198
199
# File 'lib/tea/m_event_keyboard.rb', line 197

def char
  @char
end

#keyObject (readonly)

Returns the value of attribute key.



197
198
199
# File 'lib/tea/m_event_keyboard.rb', line 197

def key
  @key
end

#modsObject (readonly)

Returns the value of attribute mods.



197
198
199
# File 'lib/tea/m_event_keyboard.rb', line 197

def mods
  @mods
end