Class: AutoBrowse::MouseMover::BrowserMouseMover
- Inherits:
-
Object
- Object
- AutoBrowse::MouseMover::BrowserMouseMover
- Includes:
- MathUtils
- Defined in:
- lib/auto_browse/mouse.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
browser must have the following methods: #move(x, y) - moves the mouse cursor to the given (x, y) coordinates #.
-
#current_coords ⇒ Object
readonly
Returns the value of attribute current_coords.
Instance Method Summary collapse
-
#initialize(browser, initial_x = 0, initial_y = 0) ⇒ BrowserMouseMover
constructor
A new instance of BrowserMouseMover.
- #move(x2, y2, overshoot = true) ⇒ Object
- #move_over_path(x1, y1, x2, y2, overshoot = false) ⇒ Object
- #path(x1, y1, x2, y2, fitts = true) ⇒ Object
- #set_coords(x, y) ⇒ Object
Methods included from MathUtils
#clamp, #confine, #coordinate_floor0, #fitts, #identity_floor0, #random_number_range
Constructor Details
#initialize(browser, initial_x = 0, initial_y = 0) ⇒ BrowserMouseMover
Returns a new instance of BrowserMouseMover.
168 169 170 171 |
# File 'lib/auto_browse/mouse.rb', line 168 def initialize(browser, initial_x = 0, initial_y = 0) @browser = browser set_coords(initial_x, initial_y) end |
Instance Attribute Details
#browser ⇒ Object
browser must have the following methods:
#move(x, y) - moves the mouse cursor to the given (x, y) coordinates
#
165 166 167 |
# File 'lib/auto_browse/mouse.rb', line 165 def browser @browser end |
#current_coords ⇒ Object (readonly)
Returns the value of attribute current_coords.
166 167 168 |
# File 'lib/auto_browse/mouse.rb', line 166 def current_coords @current_coords end |
Instance Method Details
#move(x2, y2, overshoot = true) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/auto_browse/mouse.rb', line 178 def move(x2, y2, overshoot = true) x1, y1 = *current_coords if overshoot start = Vector.new(x1, y1) finish = Vector.new(x2, y2) overshoot_radius = [start.direction(finish).magnitude * 0.33, 100].min.to_i overshoot_x, overshoot_y = *finish.overshoot(overshoot_radius).to_a move_over_path(x1, y1, overshoot_x, overshoot_y) move_over_path(overshoot_x, overshoot_y, x2, y2) else move_over_path(x1, y1, x2, y2) end # move_over_path(x1, y1, x2, y2, overshoot) end |
#move_over_path(x1, y1, x2, y2, overshoot = false) ⇒ Object
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/auto_browse/mouse.rb', line 194 def move_over_path(x1, y1, x2, y2, overshoot = false) # if overshoot # start = Vector.new(x1, y1) # finish = Vector.new(x2, y2) # overshoot_radius = [start.direction(finish).magnitude * 0.20, 100].min.to_i # overshoot_x, overshoot_y = *finish.overshoot(overshoot_radius).to_a # move_over_path(x1, y1, overshoot_x, overshoot_y) # move_over_path(overshoot_x, overshoot_y, x2, y2) # else path(x1, y1, x2, y2).each do |coords| x, y = *coords set_coords(x, y) end # end end |
#path(x1, y1, x2, y2, fitts = true) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/auto_browse/mouse.rb', line 211 def path(x1, y1, x2, y2, fitts = true) start = Vector.new(x1, y1) finish = Vector.new(x2, y2) if fitts default_width = 100 min_steps = 25 width = default_width curve = start.bezier_curve(finish) # length = curve.length() * 0.8 length = start.direction(finish).magnitude * 0.8 base_time = rand * min_steps steps = ((Math.log2(fitts(length, width) + 1) + base_time) * 3).ceil coordinate_points = curve.points(count: steps) coordinate_points.map {|coord| coordinate_floor0(coord) } else curve = start.bezier_curve(finish) curve.points end end |
#set_coords(x, y) ⇒ Object
173 174 175 176 |
# File 'lib/auto_browse/mouse.rb', line 173 def set_coords(x, y) browser.move(x, y) @current_coords = [x, y] end |