Class: Hemi::Event::Pattern::Key
- Inherits:
-
Object
- Object
- Hemi::Event::Pattern::Key
- Defined in:
- lib/hemi/event/pattern/key.rb
Constant Summary collapse
- MATCHED_EVENT =
"SDL2::Event::KeyDown".freeze
- ALLOWED_TYPES =
%i[up down].freeze
- MOD_KEYS =
%i[lshift rshift lctrl rctrl lalt ralt lgui rgui].freeze
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#modcode ⇒ Object
readonly
Returns the value of attribute modcode.
-
#mods ⇒ Object
readonly
Returns the value of attribute mods.
-
#scancode ⇒ Object
readonly
Returns the value of attribute scancode.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(key, type: :down, mods: nil) ⇒ Key
constructor
A new instance of Key.
- #inspect ⇒ Object
- #key_to_scancode ⇒ Object
- #mods_to_modcode ⇒ Object
Constructor Details
#initialize(key, type: :down, mods: nil) ⇒ Key
Returns a new instance of Key.
9 10 11 12 13 14 15 |
# File 'lib/hemi/event/pattern/key.rb', line 9 def initialize(key, type: :down, mods: nil) @type = type.to_s @key = key.to_s @mods = mods key_to_scancode mods_to_modcode end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
17 18 19 |
# File 'lib/hemi/event/pattern/key.rb', line 17 def key @key end |
#modcode ⇒ Object (readonly)
Returns the value of attribute modcode.
17 18 19 |
# File 'lib/hemi/event/pattern/key.rb', line 17 def modcode @modcode end |
#mods ⇒ Object (readonly)
Returns the value of attribute mods.
17 18 19 |
# File 'lib/hemi/event/pattern/key.rb', line 17 def mods @mods end |
#scancode ⇒ Object (readonly)
Returns the value of attribute scancode.
17 18 19 |
# File 'lib/hemi/event/pattern/key.rb', line 17 def scancode @scancode end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
17 18 19 |
# File 'lib/hemi/event/pattern/key.rb', line 17 def type @type end |
Instance Method Details
#hash ⇒ Object
19 20 21 |
# File 'lib/hemi/event/pattern/key.rb', line 19 def hash KeyPattern.new(scancode, modcode).hash end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/hemi/event/pattern/key.rb', line 23 def inspect "#<#{self.class}:#{hash} key=#{key} mods=#{mods.join(', ')}>" end |
#key_to_scancode ⇒ Object
27 28 29 |
# File 'lib/hemi/event/pattern/key.rb', line 27 def key_to_scancode @scancode = SDL2::Key::Scan.const_get(key.upcase) end |
#mods_to_modcode ⇒ Object
31 32 33 34 35 |
# File 'lib/hemi/event/pattern/key.rb', line 31 def mods_to_modcode @modcode = mods&.sum do |modkey| SDL2::Key::Mod.const_get(modkey.upcase) end || 0 end |