Class: Fusuma::Plugin::Executors::SendkeyExecutor

Inherits:
Executor
  • Object
show all
Defined in:
lib/fusuma/plugin/executors/sendkey_executor.rb

Overview

Execute to send key event to device

Instance Method Summary collapse

Constructor Details

#initializeSendkeyExecutor

Returns a new instance of SendkeyExecutor.



10
11
12
13
# File 'lib/fusuma/plugin/executors/sendkey_executor.rb', line 10

def initialize
  @device_name = config_params(:device_name)
  super
end

Instance Method Details

#config_param_typesObject



19
20
21
22
23
# File 'lib/fusuma/plugin/executors/sendkey_executor.rb', line 19

def config_param_types
  {
    device_name: [String, Array]
  }
end

#executable?(event) ⇒ TrueClass, FalseClass

check executable

Parameters:

  • event (Event)

Returns:

  • (TrueClass, FalseClass)


52
53
54
55
56
# File 'lib/fusuma/plugin/executors/sendkey_executor.rb', line 52

def executable?(event)
  event.tag.end_with?("_detector") &&
    event.record.type == :index &&
    keyboard.valid?(search_param(event))
end

#execute(event) ⇒ nil

fork and execute sendkey command

Parameters:

  • event (Event)

Returns:

  • (nil)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fusuma/plugin/executors/sendkey_executor.rb', line 28

def execute(event)
  params = search_param(event)
  MultiLogger.info(sendkey: params)
  case params
  when Array
    keyboard.types(params)
  when String
    keyboard.type(
      param: params,
      keep: search_keypress(event),
      clear: clearmodifiers(event)
    )
  else
    MultiLogger.error("sendkey: Invalid config: #{params}")
    nil
  end
rescue Errno::ENODEV => e # device is removed
  MultiLogger.error "Device is removed: #{e.message}"
  @keyboard = nil
end

#execute_keysObject



15
16
17
# File 'lib/fusuma/plugin/executors/sendkey_executor.rb', line 15

def execute_keys
  [:sendkey]
end