From 7ac8a2f7c2503687d9523b29d6678220185e02bb Mon Sep 17 00:00:00 2001 From: Sascha Nitsch Date: Mon, 9 Sep 2024 17:17:06 +0200 Subject: [PATCH] support for mouse up and down functions --- scriptedbrowser/commands/base.php | 12 ++++++++++++ scriptedbrowser/control.php | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/scriptedbrowser/commands/base.php b/scriptedbrowser/commands/base.php index 5aef090..5869aed 100644 --- a/scriptedbrowser/commands/base.php +++ b/scriptedbrowser/commands/base.php @@ -53,6 +53,18 @@ function leftclick($main, $control, $options) : bool return true; } +function leftpress($main, $control, $options) : bool +{ + $control->mouseDown(\ScriptedBrowser\MouseButton::Left); + return true; +} + +function leftrelease($main, $control, $options) : bool +{ + $control->mouseUp(\ScriptedBrowser\MouseButton::Left); + return true; +} + /** * move mouse to given element * diff --git a/scriptedbrowser/control.php b/scriptedbrowser/control.php index 75491b2..b6fab66 100644 --- a/scriptedbrowser/control.php +++ b/scriptedbrowser/control.php @@ -194,6 +194,18 @@ class Control { fwrite($this->xdotool, "key $key\n"); } + + /** + * press mouse button + * + * @param MouseButton $button button to press + * @return void + */ + public function mouseDown($button) + { + fwrite($this->xdotool, 'mousedown ' . $button->value . "\n"); + } + /** * move mouse to absolute position * @@ -217,6 +229,17 @@ class Control fwrite($this->xdotool, "mousemove_relative $x $y\n"); } + /** + * release mouse button + * + * @param MouseButton $button button to press + * @return void + */ + public function mouseUp($button) + { + fwrite($this->xdotool, 'mouseup ' . $button->value . "\n"); + } + /** * open geckodriver if not already running *