Class: Revdev::InputEvent

Inherits:
Object
  • Object
show all
Includes:
EachValuesEqual
Defined in:
lib/revdev/input_event.rb,
lib/revdev.rb

Overview

wraper of “struct input_event” on “input.h”

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EachValuesEqual

#==

Constructor Details

#initialize(arg = nil, type = nil, code = nil, value = nil) ⇒ InputEvent

arg: String(byte string), Hash, Time type, code, value: Integer (ignored values if arg is String or Hash)



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/revdev/input_event.rb', line 12

def initialize arg=nil, type = nil, code = nil, value = nil
  if arg.kind_of? String
    raw_initialize arg
  elsif arg.kind_of? Hash
    [:time, :type, :code, :value].each do |iv|
      instance_variable_set("@#{iv}", arg[iv] || arg[iv.to_s])
    end
    @time ||= Time.now
  else
    @time = arg || Time.now
    @type = type
    @code = code
    @value = value
  end
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



8
9
10
# File 'lib/revdev/input_event.rb', line 8

def code
  @code
end

#timeObject

Returns the value of attribute time.



8
9
10
# File 'lib/revdev/input_event.rb', line 8

def time
  @time
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/revdev/input_event.rb', line 8

def type
  @type
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/revdev/input_event.rb', line 8

def value
  @value
end

Instance Method Details

#hr_codeObject

human readable @code of input event



34
35
36
37
38
39
40
# File 'lib/revdev/input_event.rb', line 34

def hr_code
  ht = hr_type
  suffix = Revdev.extract_suffix ht
  return nil if suffix.nil?
  map = REVERSE_MAPS[suffix]
  map && map[@code]
end

#hr_typeObject

human readable @type of input event



29
30
31
# File 'lib/revdev/input_event.rb', line 29

def hr_type
  REVERSE_MAPS[:EV][@type]
end

#hr_valueObject

human readable @code of input event not implement



44
45
46
# File 'lib/revdev/input_event.rb', line 44

def hr_value
  nil
end