Simulate input/Mouse: Difference between revisions

m
syntax highlighting fixup automation
(Simulate input/Mouse in FreeBASIC)
m (syntax highlighting fixup automation)
Line 3:
=={{header|AutoHotkey}}==
target gui may be externally created.
<langsyntaxhighlight AutoHotkeylang="autohotkey">WinActivate, ahk_class MozillaUIWindowClass
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.</langsyntaxhighlight>
 
=={{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">
<lang C>
#define WINVER 0x500
#include<windows.h>
Line 50:
return 0;
}
</syntaxhighlight>
</lang>
 
=={{header|Common Lisp}}==
{{libheader|xdotool}}
The xdotool have to be installed on the machine (installable through apt-get). Tested on Lubuntu 14.04.
<langsyntaxhighlight lang="lisp">
(defun sh (cmd)
#+clisp (shell cmd)
Line 64:
(sleep 2)
(sh "xdotool mousemove 300 300 click 1")
</syntaxhighlight>
</lang>
 
=={{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:
 
<langsyntaxhighlight lang="fantom">
using fwt
using gfx
Line 104:
}
}
</syntaxhighlight>
</lang>
 
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:
 
<langsyntaxhighlight lang="fantom">
using [java] java.awt::Robot
using [java] java.awt.event::InputEvent
Line 137:
}
}
</syntaxhighlight>
</lang>
 
=={{header|FreeBASIC}}==
Código sacado de https://www.freebasic.net/forum/
<langsyntaxhighlight lang="freebasic">#include "fbgfx.bi"
#define rect 4
 
Line 291:
Sleep 1, 1
Loop Until Inkey = Chr(27)
</syntaxhighlight>
</lang>
Output:
 
Line 300:
<br>
The target GUI may be externally created.
<langsyntaxhighlight lang="go">package main
 
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
}</langsyntaxhighlight>
 
=={{header|GUISS}}==
 
<langsyntaxhighlight lang="guiss">Start,Programs,Accessories,Notepad,Textbox,Type:Hello World[pling],Menu:File,Save,
Inputbox:filename>greetings.txt,Button:Save</langsyntaxhighlight>
 
=={{header|Java}}==
You can click on any Component using a Robot and the Component's location:
<langsyntaxhighlight lang="java">Point p = component.getLocation();
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);</langsyntaxhighlight>
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:
<langsyntaxhighlight lang="java">button.doClick(); //optionally, give an integer argument for the number of milliseconds to hold the button down</langsyntaxhighlight>
 
=={{header|Julia}}==
This may be done using Julia's C call FFI:
 
<langsyntaxhighlight lang="julia">
# 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>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.awt.Robot
Line 359:
sendClick(InputEvent.BUTTON3_DOWN_MASK) // simulate a click of the mouse's right button
}
</syntaxhighlight>
</lang>
 
=={{header|Oz}}==
Using Tk events, this only works with internal windows.
<langsyntaxhighlight lang="oz">declare
[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>")}</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/pGUI}}
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<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>
<!--</langsyntaxhighlight>-->
 
=={{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).
<langsyntaxhighlight PicoLisplang="picolisp">(load "@lib/http.l" "@lib/scrape.l")
 
# 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</langsyntaxhighlight>
Output:
<pre>12.50</pre>
Line 472:
=={{header|PureBasic}}==
This code is Windows only.
<langsyntaxhighlight PureBasiclang="purebasic">Macro Click()
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()</langsyntaxhighlight>
{{libheader|AutoWin}}
<langsyntaxhighlight PureBasiclang="purebasic">; The same function as above, but using AutoWin UserLibray
AW_MouseClick()
Delay(1000)
AW_MouseClick(#PB_MouseButton_Left, 50, 50)</langsyntaxhighlight>
 
=={{header|Python}}==
In Windows (GUI can be externally created):
<langsyntaxhighlight Pythonlang="python">import ctypes
 
def click():
Line 500:
ctypes.windll.user32.mouse_event(0x4, 0,0,0,0) # Mouse LClick Up, relative coords, dx=0, dy=0
 
click()</langsyntaxhighlight>
 
 
{{libheader|AutoPy}}
<langsyntaxhighlight Pythonlang="python">import autopy
import math
import time
Line 526:
time.sleep(random.uniform(0.001, 0.003))
 
sine_mouse_wave()</langsyntaxhighlight>
 
{{libheader|PyAutoGUI}}
<langsyntaxhighlight Pythonlang="python">import pyautogui
 
pyautogui.moveTo(100, 200) # moves mouse to X of 100, Y of 200.
Line 551:
 
 
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
Line 558:
Same as the Python entry: use a User32 function to simulate a mouse click.
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang at-exp racket
 
Line 569:
(mouse-event #x2 0 0 0 #f)
(mouse-event #x4 0 0 0 #f)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
Line 576:
Using bindings to libxdo so any window managed by an X11 display server can receive mouse events.
 
<syntaxhighlight lang="raku" perl6line>use X11::libxdo;
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>
</lang>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : Simulate input/Mouse
 
Line 669:
line1.settext("")
line2.settext("Mouse was released")
</syntaxhighlight>
</lang>
Output:
 
Line 678:
{{libheader|AutoPilot}}
 
<langsyntaxhighlight Rustlang="rust">extern crate autopilot;
extern crate rand;
use rand::Rng;
Line 702:
fn main() {
sine_mouse_wave().expect("Unable to move mouse");
}</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight Scalalang="scala"> val (p , robot)= (component.location, new Robot())
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)</langsyntaxhighlight>
 
=={{header|Tcl}}==
===Within an Application===
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl"># Simulate a full click cycle: button down and up
event generate .okBtn <ButtonPress-1> -x 5 -y 5
event generate .okBtn <ButtonRelease-1> -x 5 -y 5</langsyntaxhighlight>
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 ="tcl">.okBtn invoke</langsyntaxhighlight>
 
=={{header|Wren}}==
Line 728:
 
Xlib can of course work with any X server, local or remote.
<langsyntaxhighlight lang="ecmascript">/* simulate_input_mouse.wren */
 
var KeyPressMask = 1 << 0
Line 907:
 
/* close connection to server */
xd.closeDisplay()</langsyntaxhighlight>
<br>
We now embed this Wren script in the following C program, compile and run it.
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 1,284:
free(script);
return 0;
}</langsyntaxhighlight>
 
{{omit from|ACL2}}
10,327

edits