module WebkitRemote::Client::Input
API for the Input
domain.
Public Instance Methods
Dispatches a keyboard event.
@param [Symbol] type the event type (:char, :down, :up, :raw_down) @param [Hash] opts optional information @option opts [Array<Symbol>] modifiers combination of :alt, :ctrl, :shift,
and :command / :meta (empty by default)
@option opts [Number] time the event's time, as a JavaScript timestamp @option opts [Number] clicks number of times the mouse button was clicked
(0 by default)
@option opts [String] text as generated by processing a virtual key code
with a keyboard layout; not needed for :up and :raw_down events; ('' by default)
@option opts [String] unmodified_text text that would have been generated
by the keyboard if no modifiers were pressed (except for shift); useful for shortcut (accelerator) key handling; ('' by default)
@option opts [Number] vkey the Windows virtual key code for the key;
see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Virtual_key_codes
@option opts [Number] key the unique key identifier (e.g., 'U+0041');
('' by default)
@option opts [Boolean] auto_repeat true if the event was generated by an
auto-repeat while the key was being held down
@option opts [Boolean] keypad true if the event was generated from the
keypad
@option opts [Boolean] system_key true if the event was a system key event @return [WebkitRemote::Client] self
# File lib/webkit_remote/client/input.rb, line 87 def key_event(type, opts) options = {} options[:type] = case type when :char 'char' when :down 'keyDown' when :up 'keyUp' when :raw_down 'rawKeyDown' else raise RuntimeError, "Unsupported keyboard event type #{type}" end options[:timestamp] = opts[:time] if opts[:time] if opts[:modifiers] flags = 0 opts[:modifiers].each do |modifier| flags |= case modifier when :alt 1 when :ctrl 2 when :command, :meta 4 when :shift 8 end end options[:modifiers] = flags end options[:key] = opts[:key] if opts[:key] options[:windowsVirtualKeyCode] = opts[:vkey] if opts[:vkey] options[:unmodifiedText] = opts[:unmodified_text] if opts[:unmodified_text] if opts[:text] options[:text] = opts[:text] options[:unmodifiedText] ||= opts[:text] end options[:autoRepeat] = true if opts[:auto_repeat] options[:isKeypad] = true if opts[:keypad] options[:isSystemKey] = true if opts[:system_key] @rpc.call 'Input.dispatchKeyEvent', options self end
Dispatches a mouse event.
@param [Symbol] type the event type (:move, :down, :up) @param [Integer] x the X coordinate, relative to the main frame's viewport @param [Integer] y the Y coordinate, relative to the main frame's viewport @param [Hash] opts optional information @option opts [Symbol] button :left, :right, :middle, or nil (none); nil by
default
@option opts [Array<Symbol>] modifiers combination of :alt, :ctrl, :shift,
and :command / :meta (empty by default)
@option opts [Number] time the event's time, as a JavaScript timestamp @option opts [Number] clicks number of times the mouse button was clicked
(0 by default)
@return [WebkitRemote::Client] self
# File lib/webkit_remote/client/input.rb, line 21 def mouse_event(type, x, y, opts = {}) options = { x: x, y: y } options[:type] = case type when :move 'mouseMoved' when :down 'mousePressed' when :up 'mouseReleased' else raise RuntimeError, "Unsupported mouse event type #{type}" end options[:timestamp] = opts[:time] if opts[:time] options[:clickCount] = opts[:clicks] if opts[:clicks] if opts[:button] options[:button] = opts[:button].to_s else options[:button] = 'none' end if opts[:modifiers] flags = 0 opts[:modifiers].each do |modifier| flags |= case modifier when :alt 1 when :ctrl 2 when :command, :meta 4 when :shift 8 end end options[:modifiers] = flags end @rpc.call 'Input.dispatchMouseEvent', options self end