function to move mouse to defined coordinates

develop
Sascha Nitsch 2024-09-09 17:19:28 +02:00
parent 184b3e8848
commit c47142ea5c
1 changed files with 33 additions and 2 deletions

View File

@ -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<string,mixed> $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<string,mixed> $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;
}
/**