Simulate input/Mouse: Difference between revisions

Content added Content deleted
(PicoLisp: Update to https://7fach.de/app/)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 1: Line 1:
{{task|GUI}}[[Category:Testing]]Simulate the click of a mouse button by the user. Specify if the target GUI may be externally created.
{{task|GUI}}[[Category:Testing]]Simulate the click of a mouse button by the user. Specify if the target GUI may be externally created.

=={{header|AutoHotkey}}==
=={{header|AutoHotkey}}==
target gui may be externally created.
target gui may be externally created.
Line 170: Line 171:
If you have a reference to the AbstractButton this is simpler:
If you have a reference to the AbstractButton this is simpler:
<lang java>button.doClick(); //optionally, give an integer argument for the number of milliseconds to hold the button down</lang>
<lang java>button.doClick(); //optionally, give an integer argument for the number of milliseconds to hold the button down</lang>



=={{header|Julia}}==
=={{header|Julia}}==
Line 203: Line 203:
}
}
</lang>
</lang>



=={{header|Oz}}==
=={{header|Oz}}==
Line 217: Line 216:
{Delay 500}
{Delay 500}
{Tk.send event(generate Button "<ButtonRelease-1>")}</lang>
{Tk.send event(generate Button "<ButtonRelease-1>")}</lang>

=={{header|Perl 6}}==
{{works with|Rakudo|2018.12}}
Using bindings to libxdo so any window managed by an X11 display server can receive mouse events.

<lang perl6>use X11::libxdo;
my $xdo = Xdo.new;

my ($dw, $dh) = $xdo.get-desktop-dimensions( 0 );

sleep .25;

for ^$dw -> $mx {
my $my = (($mx / $dh * τ).sin * 500).abs.Int + 200;
$xdo.move-mouse( $mx, $my, 0 );
my ($x, $y, $window-id, $screen) = $xdo.get-mouse-info;
my $name = (try $xdo.get-window-name($window-id) if $window-id)
// 'No name set';

my $line = "Mouse location: x=$x : y=$y\nWindow under mouse:\nWindow ID: " ~
$window-id ~ "\nWindow name: " ~ $name ~ "\nScreen #: $screen";

print "\e[H\e[J", $line;
sleep .001;
}

say '';

#`[ There are several available routines controlling mouse position and button events.

.move-mouse( $x, $y, $screen ) # Move the mouse to a specific location.

.move-mouse-relative( $delta-x, $delta-y ) # Move the mouse relative to it's current position.

.move-mouse-relative-to-window( $x, $y, $window ) # Move the mouse to a specific location relative to the top-left corner of a window.

.get-mouse-location() # Get the current mouse location (coordinates and screen ID number).

.get-mouse-info() # Get all mouse location-related data.

.wait-for-mouse-to-move-from( $origin-x, $origin-y ) # Wait for the mouse to move from a location.

.wait-for-mouse-to-move-to( $dest-x, $dest-y ) # Wait for the mouse to move to a location.

.mouse-button-down( $window, $button ) # Send a mouse press (aka mouse down) for a given button at the current mouse location.

.mouse-button-up( $window, $button ) # Send a mouse release (aka mouse up) for a given button at the current mouse location.

.mouse-button-click( $window, $button ) # Send a click for a specific mouse button at the current mouse location.

.mouse-button-multiple( $window, $button, $repeat = 2, $delay? ) # Send a one or more clicks of a specific mouse button at the current mouse location.
]
</lang>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
Line 399: Line 345:
(mouse-event #x2 0 0 0 #f)
(mouse-event #x2 0 0 0 #f)
(mouse-event #x4 0 0 0 #f)
(mouse-event #x4 0 0 0 #f)
</lang>

=={{header|Raku}}==
(formerly Perl 6)
{{works with|Rakudo|2018.12}}
Using bindings to libxdo so any window managed by an X11 display server can receive mouse events.

<lang perl6>use X11::libxdo;
my $xdo = Xdo.new;

my ($dw, $dh) = $xdo.get-desktop-dimensions( 0 );

sleep .25;

for ^$dw -> $mx {
my $my = (($mx / $dh * τ).sin * 500).abs.Int + 200;
$xdo.move-mouse( $mx, $my, 0 );
my ($x, $y, $window-id, $screen) = $xdo.get-mouse-info;
my $name = (try $xdo.get-window-name($window-id) if $window-id)
// 'No name set';

my $line = "Mouse location: x=$x : y=$y\nWindow under mouse:\nWindow ID: " ~
$window-id ~ "\nWindow name: " ~ $name ~ "\nScreen #: $screen";

print "\e[H\e[J", $line;
sleep .001;
}

say '';

#`[ There are several available routines controlling mouse position and button events.

.move-mouse( $x, $y, $screen ) # Move the mouse to a specific location.

.move-mouse-relative( $delta-x, $delta-y ) # Move the mouse relative to it's current position.

.move-mouse-relative-to-window( $x, $y, $window ) # Move the mouse to a specific location relative to the top-left corner of a window.

.get-mouse-location() # Get the current mouse location (coordinates and screen ID number).

.get-mouse-info() # Get all mouse location-related data.

.wait-for-mouse-to-move-from( $origin-x, $origin-y ) # Wait for the mouse to move from a location.

.wait-for-mouse-to-move-to( $dest-x, $dest-y ) # Wait for the mouse to move to a location.

.mouse-button-down( $window, $button ) # Send a mouse press (aka mouse down) for a given button at the current mouse location.

.mouse-button-up( $window, $button ) # Send a mouse release (aka mouse up) for a given button at the current mouse location.

.mouse-button-click( $window, $button ) # Send a click for a specific mouse button at the current mouse location.

.mouse-button-multiple( $window, $button, $repeat = 2, $delay? ) # Send a one or more clicks of a specific mouse button at the current mouse location.
]
</lang>
</lang>