Simulate input/Mouse: Difference between revisions

added Fantom example
m (omits for Brainfuck, batch files and PostScript)
(added Fantom example)
Line 9:
CoordMode, Mouse, Screen
Click 400, 400 right ; relative to top left corner of the screen.</lang>
 
=={{header|Fantom}}==
 
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:
 
<lang fantom>
using fwt
using gfx
 
class Main
{
public static Void main ()
{
button1 := Button
{
text = "don't click!"
onAction.add |Event e|
{
echo ("clicked by code")
}
}
button2 := Button
{
text = "click"
onAction.add |Event e|
{
// fire all the event listeners on button1
button1.onAction.fire(e)
}
}
Window
{
title = "simulate mouse event"
size = Size (300, 200)
button1,
button2,
}.open
}
}
</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:
 
<lang fantom>
using [java] java.awt::Robot
using [java] java.awt.event::InputEvent
using fwt
using gfx
 
class Main
{
public static Void main ()
{
button := Button
{
text = "click for robot"
onAction.add |Event e|
{
robot := Robot ()
robot.mouseMove (50, 50) // move to screen point 50, 50
robot.mousePress (InputEvent.BUTTON1_MASK) // and click mouse
robot.mouseRelease (InputEvent.BUTTON1_MASK)
}
}
Window
{
title = "simulate mouse event"
size = Size (300, 200)
button,
}.open
}
}
</lang>
 
=={{header|Java}}==
You can click on any Component using a Robot and the Component's location:
342

edits