Class: Xkeyrap::Command
- Inherits:
-
Object
- Object
- Xkeyrap::Command
- Defined in:
- lib/xkeyrap/command.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#output_device ⇒ Object
Returns the value of attribute output_device.
Instance Method Summary collapse
- #default_config ⇒ Object
-
#initialize(device, config_file) ⇒ Command
constructor
A new instance of Command.
- #receive(state, key, wm_class_name = "global") ⇒ Object
Constructor Details
#initialize(device, config_file) ⇒ Command
11 12 13 14 |
# File 'lib/xkeyrap/command.rb', line 11 def initialize(device, config_file) self.config = default_config.merge(JSON.parse(config_file)) rescue default_config self.output_device = device end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9 10 11 |
# File 'lib/xkeyrap/command.rb', line 9 def config @config end |
#output_device ⇒ Object
Returns the value of attribute output_device.
8 9 10 |
# File 'lib/xkeyrap/command.rb', line 8 def output_device @output_device end |
Instance Method Details
#default_config ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/xkeyrap/command.rb', line 26 def default_config { global: { KEY_CAPSLOCK: :KEY_LEFTCTRL, KEY_LEFTCTRL: :KEY_CAPSLOCK, KEY_LEFTALT: :KEY_LEFTMETA, KEY_LEFTMETA: :KEY_LEFTALT } } end |
#receive(state, key, wm_class_name = "global") ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/xkeyrap/command.rb', line 16 def receive(state, key, wm_class_name = "global") key = key.to_sym puts "input: #{state} ... #{key}" sub_json = self.config[wm_class_name.to_sym] || self.config[:global] mapped_key = sub_json[key] || self.config[:global][key] || key puts "output: #{state} ... #{mapped_key}" self.output_device.send_event(:EV_KEY, mapped_key.to_sym, state) self.output_device.send_event(:EV_SYN, :SYN_REPORT) end |