Robot.class commands ignored by program

Hi,
I wrote a program that uses Robot.class to control some client application.
It worked fine under windows XP.
That was a while back and now I've tried it again and it doesn't work.
Two things changes since then:
I am using windows 7 now.
I have a new version of the client application.
My questions are:
1. Is it possible to ignore commands coming from the robot class? How would the ignoring program know to do this? (normal mouse commands work of course)
2. Is there some problem in windows 7 using the robot class? (i doubt it since in works on other windows but...)
3. Is there any other way to send mouse/keyboard commands to other programs from java code?
Thanks in advance for any help.

As Andrew says, the Robot works fine on Windows 7, as 'fine' as such a class can work. What I mean by that?
Applications based on the Robot class are inherently fragile and subject to failures when: screen resolution changes, UI themes are invoved, aero, client application changes or 'adapts' itself to another environment. This is especially true when it comes to mouse handling: a click at x,y that was hitting a button in environment A may hit nothing in B.
So yes, the Robot works in Windows 7, but you may have to rewrite the application.
By the way, after trying hard some ltime ago to use java and the Robot for such things and having to struggle with JNI to get something reasonable, I completely gave up and re-wrote it in C#. Even in C# I absolutely stayed away from the mouse, but my client application had keyboard support for al I needed. And even in C# I had to call native API's, but it's easier.
Edited by: baftos on Nov 14, 2010 11:59 AM

Similar Messages

  • Priority class command doesn't work with a certain program

    Hello folks,
    I'm trying to automatize the priority class setting of a program named FreeTrack through a command written in the shortcut. Hence in its "target" I've written this (I'm using Windows 7 x64):
    C:\Windows\System32\cmd.exe /c start /REALTIME /AFFINITY 8 "" "E:\Program Files (x86)\FreeTrack\FreeTrack.exe"
    As you can see I also wanted the affinity mask of the program to be set automatically upon launch, and it works fine. The issue is that the priority class remains unchanged to normal.
    I've tried removing the "affinity" command but it didn't work.
    The priority command does its job on another program (for the attempt I used Firefox).
    Is there any explanation for this anomalous behaviour? And, most importantly, is there a solution (which preferably doesn't involve installing additional programs) ?
    Thank you and regards

    All right, I've found a solution; I'll post it for anyone in need. It's not particularly elegant but still functional.
    First of all I've created a .cmd file in the folder where is located the executable of my interest.
    In it, using notepad, I've written as following:
    start /affinity 8 FreeTrack.exe
    ping 1.1.1.1 -n 1 -w 2000 > nul
    wmic process where name="FreeTrack.exe" CALL setpriority 256
    Note that the /affinity command is optional and not required (however, I needed it). Replace "FreeTrack.exe" with the name of your executable.
    The ping part pings a fake IP once and then waits 2000 milliseconds (set a higher waiting time if this one doesn't work).
    The third line changes the priority for all the processes under the name of "FreeTrack.exe" to, in my case, realtime.
    Priority legend:
    Low: 64 Below Normal: 16384 Normal: 32 Above Normal: 32768 High: 128 Realtime: 256
    Since the command prompt window appears for 2 seconds and I don't like that, I've created a .vbs file in the same folder of the .cmd file and executable. This hides the cmd window.
    I've put the following into the .vbs file (edited with notepad):
    Set WshShell = CreateObject("WScript.Shell" )
    WshShell.Run chr(34) & "FreeTrack.cmd" & Chr(34), 0
    Set WshShell = Nothing
    Replace "FreeTrack.cmd" with your .cmd file name.
    I've then created a shortcut on the desktop to the .vbs file and changed the icon to the one of the executable.
    Surely this solution won't work if the program keeps reverting back its priority while running.

  • Applet and Robot class???

    Alright, I want to write a java program uses the robot class (the class that allows for control of keybourd and mouse commands) would this work in an applet, or would it break the applet rules that ensure computer security on the web.

    i just want it to work on 1 computer, is there a way that i can override the things that dont work on the net?

  • When i click on an excel or word file in 2007 the program begins to open but then an error message says There was a problem sending the command to the program

    when i click on an excel or word file in 2007 the program begins to open but then an error message says There was a problem sending the command to the program.
    i am using office2007  with windows7 premium home edition.  i have checked file associations., all DDE settings. i have even tried this in safe mode. the same thing happens. please note once i see the error. i can then go back to the file click on
    it a second time and it WILL open. AND i can open any file if i open excel and and find the file from there. i uninstalled and re-installed office 2007 from scratch. And i checked the compatibility mode (all un-checked) still the problem persisits. this is
    a real PITA.   anyone have any solution for this? Thanks 
    ken yanow

    Hi,
    Have you try to un-select the Ignore other applications that use Dynamic Data Exchange (DDE) setting?
    Click the Microsoft Office Button, and then click Excel Options.
    Click Advanced, and then click to clear the Ignore other applications that use Dynamic Data Exchange (DDE)
    check box in the General area.
    Click OK.
    If the problem cannot resolve, the Run as administrator may selected.
    Go to Office default install location: C:\Program Files\Microsoft Office\Office12.
    Right-click EXCEL.EXE > Properties >
    Compatibility tab.
    Under Privilege Level, uncheck Run this program as an administrator
    check box.
    Best regards.
    William Zhou
    TechNet Community Support

  • Robot class in Windows Vista

    Hello,
    It seems like there are problems with the java Robot class in Windows Vista.
    Did anyone encounter them?
    Thanks

    I didn't get your response, but I will try to explain myself.
    I have a problem with a program that I wrote that uses the Robot class and doesn't run well on Vista.
    I think that the operation system isn't letting it to control the mouse/keyboard: The program didn't crash,
    Simply didn't move the mouse although it was supposed to.
    I searched google for relevant information and the only relevant result I found was the link I posted.
    That link doesn't help me because in order to view the answer I have to pay money.
    I posted it because I thought that another description of the problem might help to understand it.

  • How to execute dos command in Java program?

    In Perl, it has System(command) to call dos command.
    Does java have this thing?
    or any other way to execute dos command in java program?
    Because i must call javacto compile a file when the user inputed a java file name.

    Look in the Runtime class, it is implemented using the Singleton design pattern so you have to use the static method getRuntime to get its only instance, on that instance you can invoke methods like
    exec(String command) that will execute that command in a dos shell.
    Regards,
    Gerrit.

  • How to run command line argument programe

    Hi guys, I am doing pass command line argument programe in java but I don't know how to run this programe. Path for this programe in my my computer is C:\Users\Desktop\Mainjava\mycode\CommandProgjava*
    {code/}
    public class CommandProg
    public static void main(String[] args)
    System.out.println("d");
    for (int i = 0; i < args.length; i++)
    System.out.println(args);
    {code/}
    Where i need to go and what command i need to give so i can execute this programe(I am using window vista). I only know i have to give
    this command some where CommandProg arg1 arg2 arg3 arg4. Output should be
    Output:
    arg1
    arg2
    arg3
    arg4
    Please help me, Thanks in advance.
    Edited by: JayVirk on Dec 30, 2007 11:33 AM

    Jay,
    Your question isn't very clear, hence Joerg's well meaning but irrelevant advise.
    Do you mean:
    I've written a simple program in java which echos
    it's command-line arguments to back to the console.
    Here's my code:
    package forums;
    public class ArgsEchoer
      public static void main(String[] args) {
        for (String arg : args) {
          System.out.println(arg);
    But can't figure out how to compile and run the program.
    I'm using winblows shista, and it's cr@p.
    Please help me, Thanks in advance.So... where are you at? Have you installed the JDK (java development kit)? Which version? Is your path set? Is your classpath set?
    Start here: http://java.sun.com/developer/onlineTraining/new2java/

  • Could not find the main class: projectRFID.ProjectGUI. Program will exit.

    Hello,
    I'm quite new in Java. I have an application with GUI. When I'm using Eclipse version 3.4.0 to run the application, all it is working perfect.
    But after I generate the jar from Eclipse, using the manifest file option from there and added the ProjectGUI to it, where is the main class, and try to run from the command line I receive the next error:
    root@slax:~/workspace# java -jar rfid.jar
    Exception in thread "main" java.lang.NoClassDefFoundError: projectRFID/ProjectGUI
    Caused by: java.lang.ClassNotFoundException: projectRFID.ProjectGUI
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: projectRFID.ProjectGUI. Program will exit.
    root@slax:~/workspace#
    I run this application on a SLAX system with jdk6 update 7.
    I tried to generate the jar file even from the command line using the manifest file option but I still receive the same error.
    I hope somebody can help me!
    Thank you!

    cojogrizli wrote:
    The structure of my project in Eclipse is src/project/files.java and in jar file is src/files.java bin/class.java Dati/ and META-INF/.That's wrong. You don't need the .java files in the jar (but you can have them, if you want, they are just not used by Java).
    And each .class file must be in a directory that reflects its package. So in your example ProjectGUI.class must be in the directory projectRFID/ inside the .jar file.

  • The icon for firefox is not working. "There was a problem sending the command to the program" pops up. Cannot get in to firefox

    Since the upgrade, the icon does not work. Now this message comes up. I made Google my home page by following directions on this site. I deleted the old icon as it didnt work, and this new one came up on my desktop and it presented the message above.

    Hi,
    Before you open any of the applications, please go to Task Manager to see if their processes are stuck there. If so, shut them down and try again.
    You can also try starting the applications in Safe Mode to determine if the problem is 3rd-party add-ins related.
    Please refer to this article below to learn more:
    http://office.microsoft.com/en-001/support/why-cant-i-start-my-office-2013-application-HA104011864.aspx
    As for the Excel problem 'There was a problem sending the command to the program', please note when double-clicking an Excel workbook, a
    dynamic data exchange (DDE) message is sent to Excel, instructing it to open the workbook that you double-clicked. If you
    turn on the "Ignore other applications that use Dynamic Data Exchange (DDE)“ setting,
     the DDE message sent to Excel by Windows Explorer is ignored, and Excel does not open the workbook that you double-clicked.
    To automatically solve this issue , we recommend to run “Microsoft Fix it 20074” and follow the steps in the wizard:
    http://support.microsoft.com/kb/211494/en-us
    You can also try to fix it manually by the steps under 'Let me fix it myself'.
    If the steps above don't help, we can try to repair Office from Control Panel -> Programs and Features to check the result.
    Regards,
    Melon Chen
    TechNet Community Support

  • Robot class and keystrokes

    Can somebody help me? I have a 14000 plus line coded program. I need to generate software produced keystrokes. For example I would like to have my program hit the 'Enter' key instead of it being generated from the keyboard by a user. Now, I have just briefly been introduced to the Robot class and I am trying to understand it. I guess to use it I have to throw a AWTException. The problem is where I need to use the Robot class is in a JButton ActionListener(), which is on line 8000 nested in another frame. My question is how and where do I throw the AWTException in my program so that I can use the Robot class to generate an 'Enter' keystroke? I have noticed that in some sample programs the AWTException follows the opening
    public static void main(String[] args) throws AWTException
    statement. I tried attaching this in my program but the code nested in a AcitionListener did not recognize it.
    What I am hoping is that I can throw the exception in the following format:
    try
    Robot robot = new Robot();
    robot.keypressed(VK_ENTER);
    catch (AWTException exception)
    exception.printStackTrace();
    This is just a format I made up to show what I am looking for it has no actual copyright.
    I do not want to throw the AWTExecption for my whole program just this localized area when I need to have the software hit enter for me.
    Anyway, this is my problem can you help me out
    Derek.

    I just figured the problem out myself, by just guessing believe it or not.
    As follows :
    try
    Robot rob = new Robot():
    rob.keyPressed(VK_ENTER);
    catch(AWTException exception)
    exception.printStackTrace();
    It worked perfectly.

  • Differences between Robot class generated events and real input events

    Hello everyone!
    I'm having a problem with the translation of the description of the awt.Robot class.
    - "This class is used to generate native system input events" -
    Does this mean there is no difference between real input events and generated events from the Robot class? Difference in reference to that the generated events can't be recognized as generated events by the os or programs.
    Thanks in advance.
    Chris B.

    The Robot class will use an interface provided by the operating system to inject events. Those are very close to 'real' input events, but not quite there. There are, for instance, several games out there which have a protection mechanism against Robot's events to prevent scripting/botting. However, any application that is not paying special attention to the event's source will assume that the input events generated by Robot are actually coming from the user, so you can 'control' any application with the exception of the beforementioned games.

  • Robot class not working

    I need to make a macro with the robot class that draws a picture in a paint program. For each color in the image (256 colors total) it should change the paint color and drawing each 2x2 pixel that's that color. I made the program and it works correctly for about an hour, but then it starts slowing down a LOT, entering the wrong color codes, and drawing single pixels instead of 2x2.
    Here is the code for changing the color:
    robot.mouseMove (535, 504);
    robot.mousePress (InputEvent.BUTTON1_MASK);
    robot.mouseRelease (InputEvent.BUTTON1_MASK);
    robot.mouseMove (568, 410);
    robot.mousePress (InputEvent.BUTTON1_MASK);
    robot.mouseRelease (InputEvent.BUTTON1_MASK);
    robot.mousePress (InputEvent.BUTTON1_MASK);
    robot.mouseRelease (InputEvent.BUTTON1_MASK);
    for (i = 0; i < 6; i++)
        robot.keyPress (color.toUpperCase ().charAt (i));
    robot.keyPress (KeyEvent.VK_ENTER);
    robot.keyRelease (KeyEvent.VK_ENTER);Here is the code for drawing each pixel:
    robot.mouseMove (415 + (w * 2), 185 + (h * 2) - 1);
    robot.mousePress (InputEvent.BUTTON1_MASK);
    robot.mouseMove (415 + (w * 2), 185 + (h * 2) + 1);
    robot.delay (100);
    robot.mouseRelease (InputEvent.BUTTON1_MASK);Does anyone know why the robot stops working after about an hour?

    I'll guess that this might have something to do with it:
    for (i = 0; i < 6; i++)
        robot.keyPress (color.toUpperCase ().charAt (i));
        //need to release the key!
        robot.keyRelease (color.toUpperCase ().charAt (i));
    }Also, about your code to draw one pixel: it draws three pixels in a vertical line, at least in my paint program.

  • Problem while running dos command from java program

    Dear friends,
    I need to terminate a running jar file from my java program which is running in the windows os.
    For that i have an dos command to find process id of java program and kill by using tskill command.
    Command to find process id is,
    wmic /output:ProcessList.txt process where "name='java.exe'" get commandline,processid
    This command gives the ProcessList.txt file and it contains the processid. I have to read this file to find the processid.
    when i execute this command in dos prompt, it gives the processid in the ProcessList.txt file. But when i execute the same command in java program it keeps running mode only.
    Code to run this command is,
    public class KillProcess {
         public static void main(String args[]) {
              KillProcess kProcess = new KillProcess();
              kProcess.getRunningProcess();
              kProcess = new KillProcess();
              kProcess.readProcessFile();
         public void getRunningProcess() {
              String cmd = "wmic /output:ProcessList.txt process where \"name='java.exe'\" get commandline,processid";
              try {
                   Runtime run = Runtime.getRuntime();
                   Process process = run.exec(cmd);
                   int i = process.waitFor();
                   String s = null;
                   if(i==0) {
                        BufferedReader stdInput = new BufferedReader(new
                               InputStreamReader(process.getInputStream()));
                        while ((s = stdInput.readLine()) != null) {
                         System.out.println("--> "+s);
                   } else {
                        BufferedReader stdError = new BufferedReader(new
                               InputStreamReader(process.getErrorStream()));
                        while ((s = stdError.readLine()) != null) {
                         System.out.println("====> "+ s);
                   System.out.println("Running process End....");
              } catch(Exception e) {
                   e.printStackTrace();
         public String readProcessFile() {
              System.out.println("Read Process File...");
              File file = null;
              FileInputStream fis = null;
              BufferedReader br = null;
              String pixieLoc = "";
              try {
                   file = new File("ProcessList.txt");
                   if (file.exists() && file.length() > 0) {
                        fis = new FileInputStream(file);
                        br = new BufferedReader(new InputStreamReader(fis, "UTF-16"));
                        String line;
                        while((line = br.readLine()) != null)  {
                             System.out.println(line);
                   } else {
                        System.out.println("No such file");
              } catch (Exception e) {
                   e.printStackTrace();
              return pixieLoc;
    }     when i remove the process.waitFor(), then while reading the ProcessList.txt file, it says "No such file".
    if i give process.waitFor(), then it's in running mode and program is not completed.
    Colud anyone please tell me how to handle this situation?
    or Is there anyother way to kill the one running process in windows from java program?
    Thanks in advance,
    Sathish

    Hi masijade,
    The modified code is,
    class StreamGobbler extends Thread
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type)
            this.is = is;
            this.type = type;
        public void run()
            try
                InputStreamReader isr = new InputStreamReader(is, "UTF-16");
                BufferedReader br = new BufferedReader(isr);
                String line=null;
                while ( (line = br.readLine()) != null)
                    System.out.println(type + ">" + line);
                } catch (IOException ioe)
                    ioe.printStackTrace(); 
    public class GoodWindowsExec
        public static void main(String args[])
            try
                String osName = System.getProperty("os.name" );
                String[] cmd = new String[3];
                 if( osName.equals( "Windows 95" ) )
                    cmd[0] = "command.com" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                } else {
                    cmd[0] = "cmd.exe" ;
                    cmd[1] = "/C" ;
                    cmd[2] = "wmic process where \"name='java.exe'\" get commandline,processid";
                Runtime rt = Runtime.getRuntime();
                System.out.println("Execing " + cmd[0] + " " + cmd[1]
                                   + " " + cmd[2]);
                Process proc = rt.exec(cmd);
                System.out.println("Executing.......");
                // any error message?
                StreamGobbler errorGobbler = new
                    StreamGobbler(proc.getErrorStream(), "ERROR");           
                          // any output?
              StreamGobbler outputGobbler = new
                    StreamGobbler(proc.getInputStream(), "OUTPUT");
                          // kick them off
                errorGobbler.start();
                outputGobbler.start();
                // any error???
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);       
            } catch (Throwable t)
                t.printStackTrace();
    }when i execute the above code, i got output as,
    Execing cmd.exe /C wmic process where "name='java.exe'" get commandline,processid
    and keeps in running mode only.
    If i execute the same command in dos prompt,
    CommandLine
    ProcessId
    java -classpath ./../lib/StartApp.jar;./../lib; com.abc.middle.startapp.StartAPP  2468
    If i modify the command as,
    cmd.exe /C wmic process where "name='java.exe'" get commandline,processid  > 123.txt
    and keeps in running mode only.
    If i open the file when program in running mode, no contents in that file.
    If i terminte the program and if i open the file, then i find the processid in that file.
    Can you help me to solve this issue?

  • Doing Shift-End using Robot class

    I am trying to use the Robot class to do a Shift-End in order to select the text in a window from the cursor to the end of the line. However, the following code only moves the cursor to the end of the line without selecting the text.
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_END);
    robot.keyRelease(KeyEvent.VK_END);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    Note that I have been able to make the following code work. So the problem with the code above does not seem to be with the Shift key per se or with the ordering of the statements.
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    Any idea how to make the Shift-End work? I am using an XP PC.

    My ENTIRE code follows. Not surprisingly, the shiftEnd.actionPerformed gets a nullPointerException during execution. And being new to Java, I get the feeling I might be missing a whole bunch of stuff. For example, do I need to register for events? Do I need to generate a shift-End ActionEvent somehow? It is only the last 4 lines that are at issue here. Everything down to that point accomplishes what I want, i.e., position the mouse in a text window in the upper right-hand corner of my screen, move the cursor to the top of that window, then go down 5 lines. At that point, I want to do the shift-End to select all text in the line.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.KeyStroke;
    import javax.swing.JTextField;
    public class KeyStrokeTest {
    /** Creates a new instance of KeyStrokeTest */
    public KeyStrokeTest() {
    * @param args the command line arguments
    public static void main(String[] args)
    throws AWTException{
    Robot robot = new Robot();
    // Position mouse over Test Director test
    robot.mouseMove(600,300);
    // Press and release left mouse button to set focus in Test Director test
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    // Go to top of Test Director test
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_HOME);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_HOME);
    // Go down to first line of request
    for(int i=0;i<5;i++) {
    robot.keyPress(KeyEvent.VK_DOWN);
    robot.keyRelease(KeyEvent.VK_DOWN);
    robot.delay(1000);
    // Do a shift End
    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_END,KeyEvent.VK_SHIFT);
    JTextField textComponent = new JTextField("String");
    ActionListener shiftEnd = textComponent.getActionForKeyStroke( keyStroke );
    shiftEnd.actionPerformed( null );

  • There was a problem sending the command to the program when opening Microsoft Project 2010 files

    When opening MS Project 2010 files from the file and print server, I receive "There was a problem sending the command to the program."  Copy the same file to my local drive and the file opens fine.  This can be repeated by several other
    users.  Created a simple project file and once the size hit 1 MB, the error appeared.  The error appears on all files over 1 MB.
    I am a domain admin, so it is not a rights issue.  This does not seem to be a network latency issue, the file copies extremely fast.
    Any ideas?

    This message appears to be caused by Windows Explorer trying to send old-fashioned DDE messages to the Application.
    Since MS Project has no "Ignore DDE messages" setting you might want to go change the compatibility settings for WinProj.EXE (and any shortcut to it) to Windows 7 or greater.  Hopefully then Windows Explorer will stop trying to send DDE messages.
    Another possible culprit is older versions of the WinZip explorer extensions - I would disable them as well.
    Good luck,
       James.
    James Boman - http://www.boman.biz Software Consultant for IPMO - http://www.ipmo.com.au

Maybe you are looking for