Class: Rbindkeys::DeviceOperator
- Inherits:
-
Object
- Object
- Rbindkeys::DeviceOperator
- Defined in:
- lib/rbindkeys/device_operator.rb,
lib/rbindkeys.rb
Overview
device operations like send key event, send LED event, etc.
Constant Summary collapse
- LOG =
LogUtils.get_logger name
Instance Attribute Summary collapse
-
#device ⇒ Object
readonly
real event device.
-
#pressed_key_set ⇒ Object
readonly
key code set which was send press event but is not send release event.
-
#virtural ⇒ Object
readonly
uinput device.
Instance Method Summary collapse
-
#initialize(dev, vdev) ⇒ DeviceOperator
constructor
A new instance of DeviceOperator.
- #press_key(code) ⇒ Object
- #pressing_key(code) ⇒ Object
- #release_key(code) ⇒ Object
- #send_event(*args) ⇒ Object
- #send_key(code, state) ⇒ Object
- #update_pressed_key_set(event) ⇒ Object
Constructor Details
#initialize(dev, vdev) ⇒ DeviceOperator
Returns a new instance of DeviceOperator.
21 22 23 24 25 |
# File 'lib/rbindkeys/device_operator.rb', line 21 def initialize dev, vdev @device = dev @virtual = vdev @pressed_key_set = [] end |
Instance Attribute Details
#device ⇒ Object (readonly)
real event device
13 14 15 |
# File 'lib/rbindkeys/device_operator.rb', line 13 def device @device end |
#pressed_key_set ⇒ Object (readonly)
key code set which was send press event but is not send release event
19 20 21 |
# File 'lib/rbindkeys/device_operator.rb', line 19 def pressed_key_set @pressed_key_set end |
#virtural ⇒ Object (readonly)
uinput device
16 17 18 |
# File 'lib/rbindkeys/device_operator.rb', line 16 def virtural @virtural end |
Instance Method Details
#press_key(code) ⇒ Object
30 31 32 |
# File 'lib/rbindkeys/device_operator.rb', line 30 def press_key code send_key code, 1 end |
#pressing_key(code) ⇒ Object
33 34 35 |
# File 'lib/rbindkeys/device_operator.rb', line 33 def pressing_key code send_key code, 2 end |
#release_key(code) ⇒ Object
27 28 29 |
# File 'lib/rbindkeys/device_operator.rb', line 27 def release_key code send_key code, 0 end |
#send_event(*args) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rbindkeys/device_operator.rb', line 41 def send_event *args event = case args.length when 1 then args[0] when 3 then @cache_input_event ||= Revdev::InputEvent.new nil, 0, 0, 0 @cache_input_event.type = args[0] @cache_input_event.code = args[1] @cache_input_event.value = args[2] @cache_input_event else raise ArgumentError, "expect a InputEvent or 3 Fixnums (type, code, state)" end dev = case event.type when Revdev::EV_KEY then @virtual when Revdev::EV_LED then @device else @virtual end update_pressed_key_set event dev.write_input_event event LOG.info "write\t#{KeyEventHandler.get_state_by_value event} "+ "#{event.hr_code}(#{event.code})" if LOG.info? end |
#send_key(code, state) ⇒ Object
37 38 39 |
# File 'lib/rbindkeys/device_operator.rb', line 37 def send_key code, state send_event Revdev::EV_KEY, code, state end |
#update_pressed_key_set(event) ⇒ Object
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/rbindkeys/device_operator.rb', line 65 def update_pressed_key_set event if event.type == Revdev::EV_KEY case event.value when 0 then @pressed_key_set.delete event.code when 1 then @pressed_key_set << event.code when 2 then # do nothing else raise UnknownKeyValue, "expect 0, 1 or 2" end end end |