lib/fusuma/plugin/sendkey/keyboard.rb in fusuma-plugin-sendkey-0.10.1 vs lib/fusuma/plugin/sendkey/keyboard.rb in fusuma-plugin-sendkey-0.11.0

- old
+ new

@@ -1,11 +1,11 @@ # frozen_string_literal: true require "revdev" require "fusuma/device" -require_relative "./device" +require_relative "device" module Fusuma module Plugin module Sendkey # Emulate Keyboard @@ -25,11 +25,11 @@ ].freeze def self.find_device(name_pattern:) Fusuma::Device.reset Fusuma::Device.all.find { |d| - next unless d.capabilities.include? "keyboard" + next unless /keyboard/.match?(d.capabilities) d.name.match(/#{name_pattern}/) } end @@ -43,13 +43,27 @@ MultiLogger.info "sendkey: Keyboard: #{device.name}" @device = Device.new(path: "/dev/input/#{device.id}") end + # @param params [Array] + def types(args) + return unless args.is_a?(Array) + + args.each do |arg| + case arg + when String + type(param: arg) + when Hash + type(**arg) + end + end + end + # @param param [String] key names separated by '+' to type # @param keep [String] key names separated by '+' to keep - # @param clear [String, Symbol, TrueClass] key names separated by '+' to clear or :all to relase all modifiers + # @param clear [String, Symbol, TrueClass] key names separated by '+' to clear or :all to release all modifiers def type(param:, keep: "", clear: :none) return unless param.is_a?(String) param_keycodes = param_to_keycodes(param) type_keycodes = param_keycodes - param_to_keycodes(keep) @@ -78,14 +92,21 @@ def keyup(keycode) send_event(code: keycode, press: false) end # @param param [String] - def valid?(param:) - return unless param.is_a?(String) - - keycodes = param_to_keycodes(param) - keycodes.all? { |keycode| support?(keycode) } + def valid?(params) + case params + when Array + params.all? { |param| valid?(param) } + when String + param = params + keycodes = param_to_keycodes(param) + keycodes.all? { |keycode| support?(keycode) } + else + MultiLogger.error "sendkey: Invalid config: #{params}" + nil + end end def send_event(code:, press: true) event = Revdev::InputEvent.new( nil,