Class: Rum::HotkeyProcessor
- Inherits:
-
Object
- Object
- Rum::HotkeyProcessor
- Defined in:
- lib/rum/hotkey_core.rb,
lib/rum/windows.rb
Overview
TODO: Needs refactoring.
Instance Attribute Summary collapse
-
#hooks ⇒ Object
readonly
Returns the value of attribute hooks.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#pressed_modifiers ⇒ Object
readonly
Returns the value of attribute pressed_modifiers.
Instance Method Summary collapse
- #add_hook(hook = nil, &block) ⇒ Object
- #execute(down, repeated) ⇒ Object
- #inhibit_modifier_action ⇒ Object
-
#initialize(hotkey_set) ⇒ HotkeyProcessor
constructor
A new instance of HotkeyProcessor.
- #key_signature(key) ⇒ Object
- #process_event(event) ⇒ Object
- #release_core_modifiers ⇒ Object
-
#remove_hook(hook) ⇒ Object
Return removed hook.
Constructor Details
#initialize(hotkey_set) ⇒ HotkeyProcessor
Returns a new instance of HotkeyProcessor.
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 |
# File 'lib/rum/hotkey_core.rb', line 392 def initialize hotkey_set @hotkey_set = hotkey_set @modifiers = @hotkey_set.modifiers @layout = @hotkey_set.layout @pressed_modifiers = {} @pressed_core_modifier_ids = {} @was_executed = {} @key_signature = nil @hooks = [] @pass_key = true @key = nil @last_key = nil @down = nil @last_event_up = nil end |
Instance Attribute Details
#hooks ⇒ Object (readonly)
Returns the value of attribute hooks.
391 392 393 |
# File 'lib/rum/hotkey_core.rb', line 391 def hooks @hooks end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
391 392 393 |
# File 'lib/rum/hotkey_core.rb', line 391 def layout @layout end |
#pressed_modifiers ⇒ Object (readonly)
Returns the value of attribute pressed_modifiers.
391 392 393 |
# File 'lib/rum/hotkey_core.rb', line 391 def pressed_modifiers @pressed_modifiers end |
Instance Method Details
#add_hook(hook = nil, &block) ⇒ Object
409 410 411 412 413 |
# File 'lib/rum/hotkey_core.rb', line 409 def add_hook(hook=nil, &block) hook ||= block @hooks.unshift hook hook end |
#execute(down, repeated) ⇒ Object
424 425 426 427 428 429 |
# File 'lib/rum/hotkey_core.rb', line 424 def execute(down, repeated) (hotkey = @hotkey_set.lookup(down, @key_signature) \ and hotkey.execute(repeated)) or (hotkey = @hotkey_set.fuzzy_lookup(down, @key, @pressed_modifiers) \ and hotkey.execute(repeated)) end |
#inhibit_modifier_action ⇒ Object
19 20 21 |
# File 'lib/rum/windows.rb', line 19 def inhibit_modifier_action System.send_keypress @layout['control'] end |
#key_signature(key) ⇒ Object
420 421 422 |
# File 'lib/rum/hotkey_core.rb', line 420 def key_signature key @modifiers.select { |modifier| @pressed_modifiers[modifier] } << key end |
#process_event(event) ⇒ Object
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 |
# File 'lib/rum/hotkey_core.rb', line 431 def process_event event puts event @key = @layout.lookup_key(event.id) @down = event.down? unless @key puts "Unknown Key\n" return true end modifier = @key.modifier? # Skip generating unnecessary key_signatures if modifier and @last_event_up or @key != @last_key @key_signature = key_signature(@key) end @last_event_up = !@down print "[#{@key_signature.map { |key| key.name.capitalize }.join(', ')}]" print ' (again)' if @key == @last_key; puts if @down repeated = @was_executed[@key] eat = @was_executed[@key] = true if execute(true, repeated) if repeated eat = true elsif modifier # if repeated, the modifier has already been added to pressed_modifiers @pressed_modifiers[@key] = true @pressed_core_modifier_ids[event.id] = true if @layout.core_modifiers[@key] end else #up @was_executed[@key] = true if execute(false, false) if modifier @pressed_modifiers[@key] = nil @pressed_core_modifier_ids[event.id] = nil if @layout.core_modifiers[@key] if @layout.action_modifiers[@key] and \ (!@pass_key or @was_executed[@key]) inhibit_modifier_action end end eat = @was_executed.delete(@key) end @pass_key = if modifier @layout.core_modifiers[@key] else !eat end @hooks.dup.each { |hook| instance_eval &hook } @last_key = @key puts @pass_key end |
#release_core_modifiers ⇒ Object
483 484 485 486 487 |
# File 'lib/rum/hotkey_core.rb', line 483 def release_core_modifiers @pressed_core_modifier_ids.each do |id, pressed| send_key_event_for_id id, false if pressed end end |
#remove_hook(hook) ⇒ Object
Return removed hook.
416 417 418 |
# File 'lib/rum/hotkey_core.rb', line 416 def remove_hook(hook) @hooks.delete hook end |