lib/fusuma/plugin/sendkey/keyboard.rb in fusuma-plugin-sendkey-0.6.3 vs lib/fusuma/plugin/sendkey/keyboard.rb in fusuma-plugin-sendkey-0.6.4

- old
+ new

@@ -8,10 +8,12 @@ module Fusuma module Plugin module Sendkey # Emulate Keyboard class Keyboard + INTERVAL = 0.01 + MODIFIER_KEY_CODES = %w[ KEY_CAPSLOCK KEY_LEFTALT KEY_LEFTCTRL KEY_LEFTMETA @@ -43,15 +45,15 @@ # @param param [String] # @param keep [String] def type(param:) return unless param.is_a?(String) - param_keycodes = split_param(param) - clear_modifiers(MODIFIER_KEY_CODES - param_keycodes) - param_keycodes.each { |keycode| key_event(keycode: keycode, press: true) } + keycodes = split_param(param) + clear_modifiers(MODIFIER_KEY_CODES - keycodes) + keycodes.each { |keycode| key_event(keycode: keycode, press: true) && wait } key_sync(press: true) - param_keycodes.reverse.each { |keycode| key_event(keycode: keycode, press: false) } + keycodes.reverse.each { |keycode| key_event(keycode: keycode, press: false) && wait } key_sync(press: false) end # @param param [String] def valid?(param:) @@ -130,9 +132,13 @@ "KEY_#{code.upcase}" end def remove_prefix(keycode) keycode.gsub('KEY_', '') + end + + def wait + sleep(INTERVAL) end end end end end