Module: WebkitRemote::Client::Input
- Included in:
- WebkitRemote::Client
- Defined in:
- lib/webkit_remote/client/input.rb
Overview
API for the Input domain.
Instance Method Summary collapse
-
#key_event(type, opts) ⇒ WebkitRemote::Client
Dispatches a keyboard event.
-
#mouse_event(type, x, y, opts = {}) ⇒ WebkitRemote::Client
Dispatches a mouse event.
Instance Method Details
#key_event(type, opts) ⇒ WebkitRemote::Client
Dispatches a keyboard event.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/webkit_remote/client/input.rb', line 87 def key_event(type, opts) = {} [: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 [: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 [:modifiers] = flags end [:key] = opts[:key] if opts[:key] [:windowsVirtualKeyCode] = opts[:vkey] if opts[:vkey] [:unmodifiedText] = opts[:unmodified_text] if opts[:unmodified_text] if opts[:text] [:text] = opts[:text] [:unmodifiedText] ||= opts[:text] end [:autoRepeat] = true if opts[:auto_repeat] [:isKeypad] = true if opts[:keypad] [:isSystemKey] = true if opts[:system_key] @rpc.call 'Input.dispatchKeyEvent', self end |
#mouse_event(type, x, y, opts = {}) ⇒ WebkitRemote::Client
Dispatches a mouse event.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/webkit_remote/client/input.rb', line 21 def mouse_event(type, x, y, opts = {}) = { x: x, y: y } [:type] = case type when :move 'mouseMoved' when :down 'mousePressed' when :up 'mouseReleased' else raise RuntimeError, "Unsupported mouse event type #{type}" end [:timestamp] = opts[:time] if opts[:time] [:clickCount] = opts[:clicks] if opts[:clicks] if opts[:button] [:button] = opts[:button].to_s else [: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 [:modifiers] = flags end @rpc.call 'Input.dispatchMouseEvent', self end |