Module: Tea::Kbd
- Defined in:
- lib/tea/m_event_app.rb,
lib/tea/m_event_keyboard.rb
Defined Under Namespace
Classes: Down, Event, Gained, Lost, Up
Constant Summary collapse
- SHIFT =
Extra modifier constants for making modifier detection more consistent.
:SHIFT
- CTRL =
:CTRL
- ALT =
:ALT
Class Method Summary collapse
-
.in_app? ⇒ Boolean
Returns true if the keyboard is focused in the screen window.
-
.key_down?(key) ⇒ Boolean
Returns
true
ifkey
is being pressed down. -
.mod_active?(mod) ⇒ Boolean
Returns true if the modifier is ‘active’.
-
.update_state(tea_event) ⇒ Object
Update the keyboard state, so that Kbd.key_down? and Kbd.mod_active? provide fresh data.
Class Method Details
.in_app? ⇒ Boolean
Returns true if the keyboard is focused in the screen window.
265 266 267 |
# File 'lib/tea/m_event_keyboard.rb', line 265 def Kbd.in_app? @in_app end |
.key_down?(key) ⇒ Boolean
Returns true
if key
is being pressed down.
246 247 248 249 250 251 |
# File 'lib/tea/m_event_keyboard.rb', line 246 def Kbd.key_down?(key) if (down = @key_states[key]) == nil raise Tea::Error, "Can't find key #{key} to check", caller end down end |
.mod_active?(mod) ⇒ Boolean
Returns true if the modifier is ‘active’. For :L_SHIFT
, :R_SHIFT
, :L_CTRL
, :R_CTRL
, :L_ALT
, and :ALT_GR
(and convenience modifier constants :SHIFT
, :CTRL
and :ALT
), this means they’re being held down. For :NUM_LOCK
and :CAPS_LOCK
, this means their toggle is on.
257 258 259 260 261 262 |
# File 'lib/tea/m_event_keyboard.rb', line 257 def Kbd.mod_active?(mod) if (active = @mod_states[mod]) == nil raise Tea::Error, "Can't find modifier #{mod} to check", caller end active end |
.update_state(tea_event) ⇒ Object
Update the keyboard state, so that Kbd.key_down? and Kbd.mod_active? provide fresh data. Called automatically by Event.get.
271 272 273 274 275 276 277 278 279 |
# File 'lib/tea/m_event_keyboard.rb', line 271 def Kbd.update_state(tea_event) case tea_event when Down, Up @key_states[tea_event.key] = (tea_event.class == Down) @mod_states.merge! tea_event.mods when Lost then @in_app = false when Gained then @in_app = true end end |