By Alvin Alexander. Last updated: June 4, 2016
This is just my second JRuby program, but I thought I might as well go for the gusto. This Ruby/JRuby program creates an instance of a Java Robot
class (java.awt.Robot
), then moves the mouse to a position where it clicks the Minimize button on a full-screen window (assuming a display resolution of 1024x768). Warning: if you have something else in that location it will click that instead!
Here's the Ruby/JRuby code:
# # devdaily.com # # this program uses jruby to run the Java Robot class. # require 'java' include_class 'java.awt.Robot' include_class 'java.awt.event.InputEvent' # on my system (1024x768 resolution) this positions the mouse over # the 'minimize' button of a full-screen window robot = Robot.new robot.mouseMove(963,10); # a slow click here so you can see what's happening robot.delay(1000); robot.mousePress(InputEvent::BUTTON1_MASK); robot.delay(1000); robot.mouseRelease(InputEvent::BUTTON1_MASK);