Class: Bluebutton
- Inherits:
-
Object
- Object
- Bluebutton
- Defined in:
- lib/bluebutton.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
-
#on_keydown ⇒ Object
Returns the value of attribute on_keydown.
-
#on_keyup ⇒ Object
Returns the value of attribute on_keyup.
-
#on_longdown ⇒ Object
Returns the value of attribute on_longdown.
-
#on_longup ⇒ Object
Returns the value of attribute on_longup.
Instance Method Summary collapse
-
#initialize(name) ⇒ Bluebutton
constructor
A new instance of Bluebutton.
- #key_down(event) ⇒ Object
- #key_up(event) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(name) ⇒ Bluebutton
Returns a new instance of Bluebutton.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bluebutton.rb', line 11 def initialize name @finder = Finder.new(name) @device = @finder.from_sys raise "#{@device} is not a character device" unless File.chardev? @device raise "#{@device} is not readable. Try sudo -E bluebutton" unless File.readable? @device puts "Device #{name} find at #{@device}" if xinput_id = @finder.from_xinput puts "xinput device finded with id=#{xinput_id}... Try disable for current X..." system("xinput disable #{xinput_id}") end end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
9 10 11 |
# File 'lib/bluebutton.rb', line 9 def device @device end |
#on_keydown ⇒ Object
Returns the value of attribute on_keydown.
5 6 7 |
# File 'lib/bluebutton.rb', line 5 def on_keydown @on_keydown end |
#on_keyup ⇒ Object
Returns the value of attribute on_keyup.
6 7 8 |
# File 'lib/bluebutton.rb', line 6 def on_keyup @on_keyup end |
#on_longdown ⇒ Object
Returns the value of attribute on_longdown.
7 8 9 |
# File 'lib/bluebutton.rb', line 7 def on_longdown @on_longdown end |
#on_longup ⇒ Object
Returns the value of attribute on_longup.
8 9 10 |
# File 'lib/bluebutton.rb', line 8 def on_longup @on_longup end |
Instance Method Details
#key_down(event) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/bluebutton.rb', line 41 def key_down event if @pressed.nil? @on_keydown.call if @on_keydown @pressed = Time.now elsif @long.nil? && @pressed < (Time.now - 1) @on_longdown.call if @on_longdown @long = true end end |
#key_up(event) ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/bluebutton.rb', line 51 def key_up event if @pressed @on_keyup.call if @on_keyup if @long @on_longup.call if @on_longup end end @long = nil @pressed = nil end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/bluebutton.rb', line 26 def run File.open(@device, 'rb' ) do |input| DeviceInput.read_loop(input) do |event| if event.type == 'EV_KEY' #puts event if event.value > 0 key_down event else key_up event end end end end end |