Class: Fusuma::Plugin::Remap::ModifierState
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Remap::ModifierState
- Defined in:
- lib/fusuma/plugin/remap/modifier_state.rb
Overview
Tracks the pressed state of modifier keys
Constant Summary collapse
- MODIFIERS =
Set.new(%w[ LEFTCTRL RIGHTCTRL LEFTALT RIGHTALT LEFTSHIFT RIGHTSHIFT LEFTMETA RIGHTMETA ]).freeze
Instance Method Summary collapse
- #current_combination(key) ⇒ Object
-
#initialize ⇒ ModifierState
constructor
A new instance of ModifierState.
- #modifier?(key) ⇒ Boolean
- #pressed_modifiers ⇒ Object
- #reset ⇒ Object
- #update(key, event_value) ⇒ Object
Constructor Details
#initialize ⇒ ModifierState
Returns a new instance of ModifierState.
17 18 19 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 17 def initialize @pressed = Set.new end |
Instance Method Details
#current_combination(key) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 30 def current_combination(key) return key if modifier?(key) modifiers = pressed_modifiers if modifiers.empty? key else "#{modifiers.join("+")}+#{key}" end end |
#modifier?(key) ⇒ Boolean
45 46 47 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 45 def modifier?(key) MODIFIERS.include?(key) end |
#pressed_modifiers ⇒ Object
41 42 43 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 41 def pressed_modifiers @pressed.to_a.sort end |
#reset ⇒ Object
49 50 51 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 49 def reset @pressed.clear end |
#update(key, event_value) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/fusuma/plugin/remap/modifier_state.rb', line 21 def update(key, event_value) return unless modifier?(key) case event_value when 1 then @pressed.add(key) when 0 then @pressed.delete(key) end end |