Class: Fusuma::Plugin::Inputs::RemapKeyboardInput

Inherits:
Input
  • Object
show all
Includes:
CustomProcess
Defined in:
lib/fusuma/plugin/inputs/remap_keyboard_input.rb

Overview

Get keyboard events from remapper

Instance Method Summary collapse

Constructor Details

#initializeRemapKeyboardInput

Returns a new instance of RemapKeyboardInput.



22
23
24
25
# File 'lib/fusuma/plugin/inputs/remap_keyboard_input.rb', line 22

def initialize
  super
  setup_remapper
end

Instance Method Details

#config_param_typesObject



14
15
16
17
18
19
20
# File 'lib/fusuma/plugin/inputs/remap_keyboard_input.rb', line 14

def config_param_types
  {
    emergency_ungrab_keys: [String],
    keyboard_name_patterns: [Array, String],
    touchpad_name_patterns: [Array, String]
  }
end

#ioObject



27
28
29
# File 'lib/fusuma/plugin/inputs/remap_keyboard_input.rb', line 27

def io
  @fusuma_reader
end

#read_from_ioRecord

override Input#read_from_io

Returns:

  • (Record)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fusuma/plugin/inputs/remap_keyboard_input.rb', line 33

def read_from_io
  @unpacker ||= MessagePack::Unpacker.new(io)
  data = @unpacker.unpack

  raise "data is not Hash : #{data}" unless data.is_a? Hash

  status = (data["status"] == 1) ? "pressed" : "released"
  Events::Records::KeypressRecord.new(status: status, code: data["key"], layer: data["layer"])
rescue EOFError => e
  MultiLogger.error "#{self.class.name}: #{e}"
  MultiLogger.error "Shutdown fusuma process..."
  Process.kill("TERM", Process.pid)
end