Class: Presentify::Keyboard

Inherits:
Object
  • Object
show all
Defined in:
lib/presentify/keyboard.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Keyboard

Returns a new instance of Keyboard.



3
4
5
6
7
# File 'lib/presentify/keyboard.rb', line 3

def initialize(&block)
  @listeners = []
  block.call(self)
  Thread.new { watch_keyboard }.join
end

Instance Method Details

#on(key, &block) ⇒ Object



9
10
11
# File 'lib/presentify/keyboard.rb', line 9

def on(key, &block)
  @listeners << [key, block]
end

#trigger(key) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/presentify/keyboard.rb', line 13

def trigger(key)
  @listeners.each do |entry|
    if entry[0] == key
      entry[1].call
    end
  end
end