How to use Java Robot to click the same button multiple times

Hi All,
I am trying to use Java Robot to turn a Windows utility located on the Desktop by clicking the same button on and then off with the following code:
  1.  Robot robot1 = new Robot();
  2.  robot1.mouseMove(400,180);
    // Turn on the utility
  3.  robot1.delay(100);
  4.  robot1.mousePress(InputEvent.BUTTON1_MASK);
  5.  robot1.delay(100);
  6.  robot1.mouseRelease(InputEvent.BUTTON1_MASK);
    //Wait for 2 minutes
  7.  robot1.delay(200);
    // Move the mouse to disconnect button
  8.  robot1.mouseMove(400,180);
    // Turn off the utility
  9.  robot1.mousePress(InputEvent.BUTTON1_MASK);
10. robot.delay(100);
11. robot.mouseRelease(InputEvent.BUTTON1_MASK);However, only the first click (line 1 - 7) worked. Everything from step 8 onwards doesn't appear to be doing anything. Even instantiating another robot2 to carry out step 8 - 11 did not work either. Also have tried running steps 9 - 11 only. ie skip 8.
My aim is to turn this tool on and off at regular interval.
Any assistance would be greatly appreciated.
Thanks in advance,
Jack

Hi darth_code_r and Vincent,
Both you and Vincent are right about insufficient time between the release ( 6 ) of mouse button and step ( 9 ) press the same button again to turn it off. You are also correct in saying that it was not necessary to move the mouse again ( 8 ) since it was sitting on the right button already.
Below is the code I have ended up with which worked for me:
1.  Robot robot1 = new Robot();
2.  robot1.mouseMove(390,150);
4.  robot1.mousePress(InputEvent.BUTTON1_MASK);
6.  robot1.mouseRelease(InputEvent.BUTTON1_MASK);
     //Wait for 3 minutes
7.  robot1.delay(30000);
9.  robot1.mousePress(InputEvent.BUTTON1_MASK);
11. robot1.mouseRelease(InputEvent.BUTTON1_MASK);This utility also takes a few seconds to turn itself on and vice versa. As a result, it is necessary to give it sufficient time to turn on prior to turning it off again with the second mouse press.
Thanks to both of you very much,
Jack

Similar Messages

  • Can I use the "same" button multiple times for multiple galleries?

    OK so I am extremely untrained in CS4 and Actionscript. However I have managed to get along fairly well until I started to dynamically upload images as a gallery. This works great if I have one gallery, but for my site I have 9 galleries!!! I have a back and next button, but I want to be able to use those same buttons for all of the galleries so they look the same. I have split them up and renamed them, but I am clueless on how to script the buttons to work. Please help...and don't laugh at my poor scripting. This is what I have now because I do not know where to put the other button names without getting errors.
    stop();
    next_btn .addEventListener(MouseEvent.CLICK, nextImage);
    var imageNumber: Number=1;
    function checkNumber(): void{
        next_btn.visible=true;
        back_btn.visible=true;
        if(imageNumber==15){
            trace(imageNumber);
        next_btn.visible=false;
        if(imageNumber==1){
            trace(imageNumber);
        back_btn.visible=false;
    function nextImage(evtObj:MouseEvent):void {
        imageNumber++;
        mc_engagement.source= "photo/engagement/en0"+imageNumber+".jpg";
        mc_amish.source= "photo/amish/Amish"+imageNumber+".jpg";
        mc_chicago.source= "photo/chicago/ch"+imageNumber+".jpg";
        mc_landscapes.source= "photo/landscapes/land"+imageNumber+".jpg";
        mc_goodvsevil.source= "photo/goodvsevil/ge"+imageNumber+".png";
        mc_animals.source= "design/animals/an"+imageNumber+".png";
        mc_icons.source= "design/icons/icon0"+imageNumber+".png";
        mc_objects.source= "design/objects/pc"+imageNumber+".png";
        mc_typography.source= "design/typography/type"+imageNumber+".png";
        checkNumber();
    back_btn .addEventListener(MouseEvent.CLICK, backImage);
    function backImage(evtObj:MouseEvent):void {
        imageNumber--;
        mc_engagement.source= "photo/engagement/en0"+imageNumber+".jpg";
        mc_amish.source= "photo/amish/Amish"+imageNumber+".jpg";
        mc_chicago.source= "photo/chicago/ch"+imageNumber+".jpg";
        mc_landscapes.source= "photo/landscapes/land"+imageNumber+".jpg";
        mc_goodvsevil.source= "photo/goodvsevil/ge"+imageNumber+".png";
        mc_animals.source= "design/animals/an"+imageNumber+".png";
        mc_icons.source= "design/icons/icon0"+imageNumber+".png";
        mc_objects.source= "design/objects/pc"+imageNumber+".png";
        mc_typography.source= "design/typography/type"+imageNumber+".png";
        checkNumber();

    I'm still a novice with Flash myself, but I have two comments.
    First, at this point, won't your buttons control all galleries at the same time? Which means, if I go to image 5 in one gallery, then move to another gallery, I'll start at image 5, because the actions are all connected.
    Second, you can definitely use the same buttons for multiple galleries. It seems to me that as long as you've assigned the buttons an instance name, these actions should already work to control all the galleries (see the note above). I guess I would need to understand a bit more about how your project is built.

  • How can I automatically close a dialog box using Javascript after I click the OK button to submit it?

    How can I automatically close a dialog box using Javascript after I click the OK button to submit it? I don't want to have to X out of the dialog box after I am done.
    Thanks
    Linda

    JS can not interact with open dialogs in any way, unless it's a dialog
    created in JS using the Dialog object.
    On Thu, Jul 24, 2014 at 11:13 PM, lindaeliseruble <[email protected]>

  • How to Use an Image to Customize the Static Button Widget

    Can I just get someone to help me figure out how to use an image to customize the static button widget, please?
    I have tried using several different types of images, but none of them seem to actually change the appearance of the button.
    Thanks!
    Laura
    Captivate 5.5

    I tried to use the tools within the widget itself - it offers you the opportunity to use an image (see screenshot below).
    I also opened it in Flash and tried to replace the images for one of the button styles there w/ my own, but in re-publishing the SWF from there I broke the widget.  When I attempted to use the edited widget, there were no customization controls available after I inserted it (see screenshot two below).

  • I want to do banners ,how can we do  when click the same button (next button)  it must show differen

    i want to do banners ,how can we do  when click the same button (next button)  it must show different images . cam any one help

    Check out my blog with samples on Edgehero.
    http://www.edgehero.com/articles/interactivity

  • TS3276 how do I get Mail to stop downloading the same email multiple times?

    My mail keeps downloading the same email multiple times.  I've had as many as 10 of the same emial.  How do I stop this?

    Me too - did you ever figure it out?
    You can't even delete from the server in mountain lion.... I did it from my old mac, but it didn't work. I keep having 11,000 new emails that can not even be deleted in blocks!!!
    Was it a gmail account? Mine is, and my other 2 are fine...

  • How to automate saving the same image multiple times?

    Hello. I wish to save the same image multiple times in a folder... is there a way to automate this function? I also need the flexibility of determining the starting number in this image sequence. Thanks.

    Good day!
    I would recommend asking for help over at
    Photoshop Scripting
    And going into more detail about what you want to achieve (maybe post a screenshot, diagram, mock-up to illustrate it).
    Regards,
    Pfaffenbichler

  • Is it possible to copy the same database multiple times simultaneously?

    This is the setup of my environment.
    I have a 'master' database that contains the full schema plus some pre-populated data such as default settings. When database schema changes are made, they get made to the master database. When a new customer signs up for the service, I make a copy of this
    master database (using SMO) that will now be the database containing all of the customer's information. The database is rather large, and the copy operation can take a couple minutes.
    Everything works fine as expected, unless I try to provision two new customers at the same time. It appears that Azure only allows for one DB copy operation at a time. Is there a way to allow for copying the same database multiple times simultaneously?
    Thanks for you input. I understand that this is likely not the optimal setup, and that there is many better ways of doing this, but I am somewhat heavily invested in the current process and I would like to find out how to make it work if I can.

    BTW, you can do this programatically by using PowerShell (https://msdn.microsoft.com/en-us/library/ee210569.aspx), SqlPackage (http://www.benday.com/2012/12/18/deploy-a-sql-server-database-projects-dacpac-with-sqlpackage-exe/)
    or the SQL Server binaries for .NET (http://www.vijayt.com/Post/Deploying-a-data-tier-application-in-SQL-Azure-programatically)
    Hope this helps.
    Alex

  • Running the same code multiple times with different paramters automatica​lly

    Hi guys,
    I want to run the same code multiple times with different paramters automatically. Actually, I am doing some sample scans which takes around 2 hours n then I have to be there to change the paramters and run it again. Mostly I do use folowing paramters only
    X_Intial, X_Final, X-StepSize
    Y_Intial, Y_Final, Y-StepSize
       Thanks,
    Dushyant

    All you have to di is put all of the parameters for each run into a cluster array. Surround your main program with a for loop and wire the cluster array through the for loop. A for loop will autoindex an input array so inside the for loop you just have to unbundle the cluster to get the parameters for each run.
    Message Edited by Dennis Knutson on 07-13-2006 07:50 AM
    Attachments:
    Cluster Array.JPG ‏9 KB

  • Help - HP Pavilion a6030.uk desktop. Have to press the power button multiple times to start up?

    Hi, 
    I have a HP desktop computer. The model is HP Pavilion a6030.uk, Opertating system: windows vista.
    My computer has had no problem at all until yesterday for some reason i  had to push the power button multiple times to start it until it finally turned on and did the normal start up. Such as i would press the power button as normal to start it, but all of a sudden, it would turn off after about 2 seconds, and so I would press the power button several times and each time it would not start up and turn off, so the power button would be pressed again until it would finally turn on and start up and run as normal and seems to work fine. And it was the same today, i pressed the power button mutiple times (e.g. 6 times) until it finally started as normal.
    As im not very knowledgeable or very computer/technology savvy wise in this area, please will someone help me and give me some advice/help to fix/solve this.
    Thankyou for taking time to read this and any help would be much appreciated to resolving this problem.
    Thanks.
    This question was solved.
    View Solution.

    Vonbon90, welcome to the forum.
    When I see these symptoms on an older computer, I believe that it may be a failed/ing power supply unit (PSU).  Here is a guide that will help your troubleshoot it.
    Also, you could test the memory.  This can be done by removing all of the memory modules and replacing them one at a time and booting.
    Please click the " Thumbs up + button" if I have helped you and click "Accept as Solution" if your problem is solved.
    Signature:
    HP TouchPad - 1.2 GHz; 1 GB memory; 32 GB storage; WebOS/CyanogenMod 11(Kit Kat)
    HP 10 Plus; Android-Kit Kat; 1.0 GHz Allwinner A31 ARM Cortex A7 Quad Core Processor ; 2GB RAM Memory Long: 2 GB DDR3L SDRAM (1600MHz); 16GB disable eMMC 16GB v4.51
    HP Omen; i7-4710QH; 8 GB memory; 256 GB San Disk SSD; Win 8.1
    HP Photosmart 7520 AIO
    ++++++++++++++++++
    **Click the Thumbs Up+ to say 'Thanks' and the 'Accept as Solution' if I have solved your problem.**
    Intelligence is God given; Wisdom is the sum of our mistakes!
    I am not an HP employee.

  • Why is Apple TV showing the same computer multiple times for Home Sharing?

    Why is my Apple TV showing the same computer multiple times for Home Sharing? Also have connectivity issues. Sometimes will lose signal.
    JonRod's music
    JonRod's music
    JonRod's music
    JonRod's music
    JonRod's music
    I recently updated to Yosemite and never had this issue before.

    I'm not 100% sure of the ins and outs, but it's some sort of known issue between Yosemite, Airport and wifi. All you can do is wait for a fix and keep restarting your equipment as and when needed, unless you have the ability to connect your Mac via ethernet.

  • Can I gift the same app multiple times to multiple users?

    Can I gift the same app multiple times to multiple users?
    Like, if I wanted to buy iMovie for 3 friends, could I buy the app as a gift 3 times?

    You should be able to gift it multiple times
    Gifting content : http://support.apple.com/kb/HT2736

  • I can't play my music any more when my phone is off? I use to just double click the home button and it would play music. Now it doesn't. Why?

    I can't play music on my iPhone 4 anymore when my phone is off. I use to double click the home button and I could play music with out having to enter my pass code every time. Now it doesn't work that way any more. Can any one tell me how to fix it?

    Did you already try to reset the phone by holding the sleep and home button for about 10sec, until the Apple logo comes back again? You will not lose data by resetting your device, but it can cure some glitches.

  • How to use 10 touch points at the same time ?

    I want to project game which use about 10 touch points? How can I use all of them at the same time ?
    Please give me a sample code.

    Firstly you must know how many touch points can accept your device. For example iPad and iPhone can't handle more than 5.
    1. Enable touch input mode by
    Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
    2. Use same method as for mouse input but instead use TouchEvent API

  • How to use a calculated column in the same query

    Hi All,
    I need some help with using a calculated column in the same query.
    For eq
    I am joining a couple of tables and some of the select columns are calculated based on the columns of the tables and i want a new column in the same query to use this calculated feild in some other calcualtion.
    something like this...
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    Thanks

    user548171 wrote:
    select (12+3) as Sum1, (12-3) as Sum2, (Sum1 + Sum2 ) as Sum3
    from dual
    or
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( "Sum1" / "Sum2" * 100 > 0 ) THEN 'Yes' ELSE 'No' END
    from dual
    ThanksWhat about just repeating the column values:
    select (12+3) as "Sum1", (12-3) as "Sum2", CASE WHEN ( (12+3) / (12-3)  * 100  > 0 )  THEN 'Yes' ELSE 'No'  END FROM DUAL

Maybe you are looking for