Simulate input/Mouse: Difference between revisions
m
syntax highlighting fixup automation
(Simulate input/Mouse in FreeBASIC) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 3:
=={{header|AutoHotkey}}==
target gui may be externally created.
<
Click 200, 200 right ; relative to external window (firefox)
sleep, 2000
WinMinimize
CoordMode, Mouse, Screen
Click 400, 400 right ; relative to top left corner of the screen.</
=={{header|C}}==
===Windows===
Animates the movement of the mouse pointer from the screen center to the bottom left corner where the Windows button is usually present on most Windows desktops. Once there, a left click is simulated. The exact speed, motion and behaviour of the pointer will vary from desktop to desktop. Compatible with MinGW or GCC for Windows.
<syntaxhighlight lang="c">
#define WINVER 0x500
#include<windows.h>
Line 50:
return 0;
}
</syntaxhighlight>
=={{header|Common Lisp}}==
{{libheader|xdotool}}
The xdotool have to be installed on the machine (installable through apt-get). Tested on Lubuntu 14.04.
<
(defun sh (cmd)
#+clisp (shell cmd)
Line 64:
(sleep 2)
(sh "xdotool mousemove 300 300 click 1")
</syntaxhighlight>
=={{header|Fantom}}==
Line 70:
You can simulate a mouse click on a button by asking that button to fire its event listeners. This approach only works for the program's own GUI:
<
using fwt
using gfx
Line 104:
}
}
</syntaxhighlight>
Alternatively, if you are running on the Java Runtime, you can use Java's 'robot' library to click anywhere on the screen, and so interact with widgets from other programs:
<
using [java] java.awt::Robot
using [java] java.awt.event::InputEvent
Line 137:
}
}
</syntaxhighlight>
=={{header|FreeBASIC}}==
Código sacado de https://www.freebasic.net/forum/
<
#define rect 4
Line 291:
Sleep 1, 1
Loop Until Inkey = Chr(27)
</syntaxhighlight>
Output:
Line 300:
<br>
The target GUI may be externally created.
<
import "github.com/go-vgo/robotgo"
Line 307:
robotgo.MouseClick("left", false) // single clicks left mouse button
robotgo.MouseClick("right", true) // double clicks right mouse button
}</
=={{header|GUISS}}==
<
Inputbox:filename>greetings.txt,Button:Save</
=={{header|Java}}==
You can click on any Component using a Robot and the Component's location:
<
Robot robot = new Robot();
robot.mouseMove(p.getX(), p.getY()); //you may want to move a few pixels closer to the center by adding to these values
robot.mousePress(InputEvent.BUTTON1_MASK); //BUTTON1_MASK is the left button,
//BUTTON2_MASK is the middle button, BUTTON3_MASK is the right button
robot.mouseRelease(InputEvent.BUTTON1_MASK);</
If you don't have a reference to the component, you'll need to guess at where it is.
Line 327:
If you have a reference to the AbstractButton this is simpler:
<
=={{header|Julia}}==
This may be done using Julia's C call FFI:
<
# Wrap win32 API function mouse_event() from the User32 dll.
function mouse_event_wrapper(dwFlags,dx,dy,dwData,dwExtraInfo)
Line 342:
mouse_event_wrapper(0x4,0,0,0,0)
end
</syntaxhighlight>
=={{header|Kotlin}}==
<
import java.awt.Robot
Line 359:
sendClick(InputEvent.BUTTON3_DOWN_MASK) // simulate a click of the mouse's right button
}
</syntaxhighlight>
=={{header|Oz}}==
Using Tk events, this only works with internal windows.
<
[QTk] = {Module.link ['x-oz://system/wp/QTk.ozf']}
Button
Line 372:
{Tk.send event(generate Button "<ButtonPress-1>")}
{Delay 500}
{Tk.send event(generate Button "<ButtonRelease-1>")}</
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Simulate_mouse_input.exw
Line 439:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PicoLisp}}==
Line 451:
in the following example. Mouse input is simulated with the functions 'click'
(click on a HTML link) and 'press' (press a submit button).
<
# Connect to the demo app at https://7fach.de/app/
Line 465:
(click "Spare Part") # Click on "Spare Part" article
(prinl (value 8)) # Print the price (12.50)
(click "logout") # Log out</
Output:
<pre>12.50</pre>
Line 472:
=={{header|PureBasic}}==
This code is Windows only.
<
mouse_event_(#MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
mouse_event_(#MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
Line 484:
; Move to a new location and click it
SetCursorPos_(50, 50)
Click()</
{{libheader|AutoWin}}
<
AW_MouseClick()
Delay(1000)
AW_MouseClick(#PB_MouseButton_Left, 50, 50)</
=={{header|Python}}==
In Windows (GUI can be externally created):
<
def click():
Line 500:
ctypes.windll.user32.mouse_event(0x4, 0,0,0,0) # Mouse LClick Up, relative coords, dx=0, dy=0
click()</
{{libheader|AutoPy}}
<
import math
import time
Line 526:
time.sleep(random.uniform(0.001, 0.003))
sine_mouse_wave()</
{{libheader|PyAutoGUI}}
<
pyautogui.moveTo(100, 200) # moves mouse to X of 100, Y of 200.
Line 551:
</syntaxhighlight>
=={{header|Racket}}==
Line 558:
Same as the Python entry: use a User32 function to simulate a mouse click.
<syntaxhighlight lang="racket">
#lang at-exp racket
Line 569:
(mouse-event #x2 0 0 0 #f)
(mouse-event #x4 0 0 0 #f)
</syntaxhighlight>
=={{header|Raku}}==
Line 576:
Using bindings to libxdo so any window managed by an X11 display server can receive mouse events.
<syntaxhighlight lang="raku"
my $xdo = Xdo.new;
Line 623:
.mouse-button-multiple( $window, $button, $repeat = 2, $delay? ) # Send a one or more clicks of a specific mouse button at the current mouse location.
]
</syntaxhighlight>
=={{header|Ring}}==
<
# Project : Simulate input/Mouse
Line 669:
line1.settext("")
line2.settext("Mouse was released")
</syntaxhighlight>
Output:
Line 678:
{{libheader|AutoPilot}}
<
extern crate rand;
use rand::Rng;
Line 702:
fn main() {
sine_mouse_wave().expect("Unable to move mouse");
}</
=={{header|Scala}}==
{{libheader|Scala}}
<
robot.mouseMove(p.getX().toInt, p.getY().toInt) //you may want to move a few pixels closer to the center by adding to these values
robot.mousePress(InputEvent.BUTTON1_MASK) //BUTTON1_MASK is the left button
robot.mouseRelease(InputEvent.BUTTON1_MASK)</
=={{header|Tcl}}==
===Within an Application===
{{libheader|Tk}}
<
event generate .okBtn <ButtonPress-1> -x 5 -y 5
event generate .okBtn <ButtonRelease-1> -x 5 -y 5</
Note that many of Tk's windows also need appropriate <Enter> and <Leave> events in order to work correctly. For the process of actually simulating a click on a button, it is actually easier to work at the method-call level rather than the event generation level:
<syntaxhighlight lang
=={{header|Wren}}==
Line 728:
Xlib can of course work with any X server, local or remote.
<
var KeyPressMask = 1 << 0
Line 907:
/* close connection to server */
xd.closeDisplay()</
<br>
We now embed this Wren script in the following C program, compile and run it.
<
#include <stdlib.h>
#include <string.h>
Line 1,284:
free(script);
return 0;
}</
{{omit from|ACL2}}
|