Class: Minibidi::Input
- Inherits:
-
Object
- Object
- Minibidi::Input
- Defined in:
- lib/minibidi/input.rb
Instance Method Summary collapse
- #click(x:, y:, delay: 50) ⇒ Object
-
#initialize(browser_context) ⇒ Input
constructor
A new instance of Input.
- #press_key(key, delay: 50) ⇒ Object
- #type_text(text, delay: 50) ⇒ Object
- #while_pressing_key(key, &block) ⇒ Object
Constructor Details
#initialize(browser_context) ⇒ Input
Returns a new instance of Input.
3 4 5 |
# File 'lib/minibidi/input.rb', line 3 def initialize(browser_context) @browser_context = browser_context end |
Instance Method Details
#click(x:, y:, delay: 50) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/minibidi/input.rb', line 7 def click(x:, y:, delay: 50) perform_mouse_actions do |q| q.pointer_move(x: x.to_i, y: y.to_i) q.pointer_down(button: 0) q.pause(delay) q.pointer_up(button: 0) end end |
#press_key(key, delay: 50) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/minibidi/input.rb', line 31 def press_key(key, delay: 50) value = convert_key(key) perform_keyboard_actions do |q| q.key_down(value) q.pause(delay) q.key_up(value) end end |
#type_text(text, delay: 50) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/minibidi/input.rb', line 40 def type_text(text, delay: 50) text.each_char do |char| perform_keyboard_actions do |q| q.key_down(char) q.pause(delay / 2) q.key_up(char) q.pause(delay / 2) end end end |
#while_pressing_key(key, &block) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/minibidi/input.rb', line 16 def while_pressing_key(key, &block) value = convert_key(key) perform_keyboard_actions do |q| q.key_down(value) end begin block.call ensure perform_keyboard_actions do |q| q.key_up(value) end end end |