diff --git a/scriptedbrowser/commands/base.php b/scriptedbrowser/commands/base.php index 28f8544..9501969 100644 --- a/scriptedbrowser/commands/base.php +++ b/scriptedbrowser/commands/base.php @@ -76,7 +76,6 @@ function leftrelease($main, $control, $options) : bool function mousemove($main, $control, $options) : bool { $element = $control->selectCSS($main->vars($options['parameter'])); - $mouseOffset = $main->getMouseOffset(); if ($element === [] || array_key_exists('error', $element)) { return false; } @@ -88,6 +87,39 @@ function mousemove($main, $control, $options) : bool $targetX -= $scroll[0]; $targetY -= $scroll[1]; // echo "move $element - $tokens[1] $targetX $targetY\n"; + _mousemoveaction($main, $control, $options, $targetX, $targetY); + return true; +} + +/** + * move mouse to given target position from variables + * + * @param \ScriptedBrowser\Main $main main instance + * @param \ScriptedBrowser\Control $control control interface + * @param array $options options + * @return bool true if mouse move, false on error + */ +function mousemovetarget($main, $control, $options) : bool +{ + $targetX = $main->vars($options['x']); + $targetY = $main->vars($options['y']); + $scroll = $control->getScrollPosition(); + $targetX -= $scroll[0]; + $targetY -= $scroll[1]; + _mousemoveaction($main, $control, $options, $targetX, $targetY); + return true; +} + +/** + * move mouse to given target position + * + * @param \ScriptedBrowser\Main $main main instance + * @param \ScriptedBrowser\Control $control control interface + * @param array $options options + */ +function _mousemoveaction($main, $control, $options, $targetX, $targetY) +{ + $mouseOffset = $main->getMouseOffset(); $mouseX = $main->getMouseX(); $mouseY = $main->getMouseY(); $delta = [$targetX - $mouseX, $targetY - $mouseY]; @@ -109,7 +141,6 @@ function mousemove($main, $control, $options) : bool $main->setMouseX($targetX); $main->setMouseY($targetY); $control->mousemove($targetX + $mouseOffset[0], $targetY + $mouseOffset[1]); - return true; } /**