How to simulate Mouse Click with Ruby, or mouse library

K

Kid Kid

Hi, I would like to simulate a Mouse click through Ruby. Is there a way
to do this through Ruby? Does Ruby have any library for simulating
mouse events. Can someone provide me with some info on this topic.
Thanks in advance.
 
B

Benjohn Barnes

Hi, I would like to simulate a Mouse click through Ruby. Is there
a way
to do this through Ruby? Does Ruby have any library for simulating
mouse events. Can someone provide me with some info on this topic.
Thanks in advance.

I think you'll need to provide a little more info to help people get
started with this one. What GUI environment are you using and trying
to make mouse clicks in?

Cheers,
Benj
 
K

Kid Kid

Thanks for the suggestion Ben, I would like to use ruby to simulate a
mouse click on any general Windows program such as Internet Explorer.
I'm aware that I can use WATIR to automate clicking on elements on the
webpages. However what i'm looking for is the ability to use Ruby to
issue a "Mouse click" no matter where the cursor is or what program is
running.

Thanks,
KidK
 
M

Marcelo Alvim

Well, AutoIt is a fine automation program for windows, although it
uses it's own language. But the latest version also provides a DLL to
do this programmatically, so you should be able to interface Ruby with
the DLL and be all set.

Marcelo.
 
K

Kid Kid

Thanks for the help Marcelo. Using AutoIt through Ruby does exactly what
I needed. Thanks!
 
C

Chad Brewbaker

Kid said:
Hi, I would like to simulate a Mouse click through Ruby. Is there a way
to do this through Ruby? Does Ruby have any library for simulating
mouse events. Can someone provide me with some info on this topic.
Thanks in advance.

KLUDGE:
Write a ruby script that outputs this to a file named Bot.java, runs
javac, then runs the JVM:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
class Bot {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException e) {
e.printStackTrace();
}
}
}

Less of a kludge: Find how java.awt.Robot is implemented in C now that
Sun has relased Java as open source.

I hope mouse functionality is part of the standard library in Ruby2.
 
B

brenton.leanhardt

Kid said:
Hi, I would like to simulate a Mouse click through Ruby. Is there a way
to do this through Ruby? Does Ruby have any library for simulating
mouse events. Can someone provide me with some info on this topic.
Thanks in advance.

KLUDGE:
Write a ruby script that outputs this to a file named Bot.java, runs
javac, then runs the JVM:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
class Bot {
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException e) {
e.printStackTrace();
}
}

}

Less of a kludge: Find how java.awt.Robot is implemented in C now that
Sun has relased Java as open source.

I hope mouse functionality is part of the standard library in Ruby2.

I would imagine you could use
public static void main(String[] args) {
try {
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (AWTException e) {
e.printStackTrace();
}
}

}

Less of a kludge: Find how java.awt.Robot is implemented in C now that
Sun has relased Java as open source.

I hope mouse functionality is part of the standard library in Ruby2.

I would imagine you could use the Robot class from jruby, though I
don't know if jruby is an option in KidK's case.

--Brenton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top