How to send keystroke to inactive window?

I need to know how to send a keystroke to an inactive window.
Right now i can use the Robot class and send key strokes to the active window but I need to be able to send it to an inactive window.

if you just want to send keys to another java app, this is a kludge hack, windows only
run frame1 and frame2 as separate apps, have them both visible on the screen, focus on frame1.
click the button to send 'enter' to frame2, which will (should) display the JOptionPane
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame1
  public void buildGUI()
    JButton btn = new JButton("Send Enter");
    JFrame f = new JFrame("Frame1");
    f.getContentPane().add(btn);
    f.setBounds(300,100,400,300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
    btn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        sendEnterToFrame2();
  public void sendEnterToFrame2()
    try
      java.io.File file = new java.io.File("ActivateFrame2.vbs");
      java.io.FileWriter fw = new java.io.FileWriter(file);
      fw.write("set ws = WScript.CreateObject(\"WScript.Shell\")\r\nws.AppActivate \"Frame2\" \r\n set ws = nothing");
      fw.close();
      Runtime.getRuntime().exec("WScript.exe ActivateFrame2.vbs");
      file.deleteOnExit();
      Robot robot = new Robot();
      robot.delay(1000);
      robot.keyPress(KeyEvent.VK_ENTER);
      robot.keyRelease(KeyEvent.VK_ENTER);
    catch(Exception e){e.printStackTrace();}
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Frame1().buildGUI();
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Frame2
  public void buildGUI()
    JButton btn = new JButton("OK");
    JFrame f = new JFrame("Frame2");
    f.getContentPane().add(btn);
    f.setBounds(700,100,400,300);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getRootPane().setDefaultButton(btn);
    f.setVisible(true);
    btn.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent ae){
        JOptionPane.showMessageDialog(null,"OK");
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Frame2().buildGUI();
}

Similar Messages

  • How to send keystrok thru program

    hi,
    can anyone tell me, how to send keystroke event to my application programatically. I have to send 'F1' key event.
    thanks in advance
    debashis roy

    Reply 10 of this thread shows you how to send a Ctrl-F1 Keystroke to a component.
    http://forum.java.sun.com/thread.jsp?forum=31&thread=224581
    To just send F1 to the component I think you just replace "KeyEvent.CTRL_MASK" with 0.

  • How to send data from popup window to parent window

    Hi,
    I need help some like this
    I have parent window ,in that i am clicking + button one dynamic row should add and one popup window has to diplay .Popup window contain 3 comboboxes and 5 text boxes. Once i am clicking OK button in popup window those values has to display at specified row in parent window
    Kindly help me ,
    Thanks
    jyothi

    See this
    http://www.oracle.com/technology/products/jdev/101/howtos/jsfdrilldown/index.html

  • I would like to send pics from my windows computer to my iPhone using bluetooth. I had it paired but somehow it cannot the download the software and is asking to usa a disk instead. Where or how can I download the software available for that, please reply

    I would like to send pics from my windows computer to my iPhone using bluetooth. I had it paired but somehow it cannot the download the software and is asking me to usa a disk instead. Where or how can I download the software available for that, please reply... thaks. (",)

    Bluetooth file transfer has never been supported with iOS devices.

  • Anyone know how to send a jpeg file to Windows via Mail without it being embedded into the receivers email

    The plain text feature in Mail application does not seem to be working. I noticed this when I send jpg attachments to Windows machines, the receiver gets the attached jpg file embedded in their email and they have no way to save the jpg image. This type of behaviour is normal when when sending rich text emails to Windows machines, but selecting plain text used to eliminate this problem in Snow Leopard.
    I have 'always send window-friendly attachemnts' selected.
    I spoke to Apple about this and they say it was designed this way.
    Can you tell me how I can send jpeg images from Lion to Windows machines so that they can save and reomve the file from their email application?

    Perhaps the boolean expression isn't working because it needs to be all caps: YES instead of yes
    In any case, a simple 1 or 0 works just fine for me without -bool:
    The command to disable in-line attachments (all attachments appear as icons)
    defaults write com.apple.mail DisableInlineAttachmentViewing 1
    To command to (re-)enable in-line attachments once disabled (all attachments appear as images or documents displayed in-line)
    defaults write com.apple.mail DisableInlineAttachmentViewing 0
    Also, when composing a new message with an attachment, be certain that 'Send Windows-Friendly Attachments' is checkmarked at the bottom of the new message screen:

  • When I attach a JPG file in my email and send it to a Windows friend they get the message "The file type being saved or retrieved has been blocked when they try to open it." Anyone know why and how to fix this problem?

    When I attach a JPG file in my email message and send it to a Windows friend they get the message "The file type being saved or retrieved has been blocked when they try to open it so that they can save it." Anyone know why and how to fix this problem?

    Your Windows friend should ask in a Windows forum why his email client won't open attached jpg files. We have no idea what email client he is using or how his Windows security is configured.

  • How to send process instructions to new pcs system

    Hi, we have PCS system known as performer. we need to send the process order header data to this pcs system. i created all z characteristics and z process instruction type and assigned to CRD. Now i could not understand how to send this info to perfomer. do i need to send this to xi and from xi i need to send to performer? is there any way to send directly to performer? please guide me so that i follow the same.

    Close inactive apps
    1. Double tap the home button to bring up the multi-tasking view
    2. Swipe the app's windows upwards to close
    3. The app will fly off the screen
    http://support.apple.com/kb/ht5137

  • On my HP Touchsmart 310 PC how do I increase the inactivity time on the display?

    On my HP Touchsmart 310 PC how do I increase the inactivity time on the display?   Windows 7, 64-bit

    Hi,
    Please try Control panel > Power options > Change when the computer sleeps
    Hope this helps.
    BH
    **Click the KUDOS thumb up on the left to say 'Thanks'**
    Make it easier for other people to find solutions by marking a Reply 'Accept as Solution' if it solves your problem.

  • Automator - How do I: Mouse Click, Move Windows, and more

    Hello,
    I am attempting to create my own Automator programs and for a while I had some that worked nicely. I have recently been tweaking my iMac so that it can "think" on its own (by automator of course) and do things for me. However, I've run across a block with Mavericks (I believe it's due to Mavericks).
    1. How can I get Automator to register a mouse click? "Watch me do" does not seem to want to work for me at all. I also would prefer if it would just be a registered mouse click, but not actually use the mouse (I know this is possible) so that if I'm doing something and it runs, it won't disturb my mouse and I can keep working.
    2. How can I register a keyboard stroke? Same as above
    3. How can I have automator move windows? I have two monitors and there are times when I may want it to move a window from one mintor to another
    The following is a list of all the things I'm attempting to accomplish at the moment (with other things when I think of them) with automator (either through applications, folder actions, or ical actions):
    1. Register a mouse click at a given area or on a given element in a safari page
    2. Register a keyboard stroke in a given program (be able to focus on a program and then do the keystroke)
    3. Move windows from one location to another
    4. Full-screen and Un-full-screen iTunes at certain times of day
    5. Download all purchased items on iTunes that aren't on the computer (sometimes iTunes doesn't download stuff if it was downloaded on my MacBook Pro first)
    6. Automatically voice read reminders (that I've set in Reminders) each day at a given time (I can use loop to repeat it to make sure I hear it all)
    I'll think of more of course, but the mouse click, keyboard stroke, and moving windows is the big thing I'm trying to figure out how to do. Can anyone help?
    Also, I am not a computer tech. I am tinkering with this because it's fun and helpful, but an answer of "just use applescript" or "just use java" will likely just give me a headache. I know that it's going to be one of those codes, but I'm hoping someone has a "base" code that can be copied and pasted that's just a standard click that I can adjust for where I need to click and what process I need to click on.
    If there is an Action Pack that includes a "Register Mouse Click" and/or "Register Keyboard Stroke", then that would work great, but the only action packs for automator I've seen that work with Mavericks is for photoshop.

    You're asking for a lot in one post.  It would be better to break your requests down a bit. 
    For example, to deal with mouse clicks, you can use the Automator Action Run Shell Script with this python script:
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
            theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
            CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
            mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
            mouseEvent(kCGEventLeftMouseDown, posx,posy);
            mouseEvent(kCGEventLeftMouseUp, posx,posy);
    ourEvent = CGEventCreate(None);
    # Save current mouse position
    currentpos=CGEventGetLocation(ourEvent);
    # Click the "Apple"
    mouseclick(25, 5);  
    # 1 second delay       
    time.sleep(1);        
    # Restore mouse position
    mousemove(int(currentpos.x),int(currentpos.y))
    It will look like this in Automator:
    To drag something (i.e. a window, a file icon) from position 40,60 to 60,300:
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
               theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
               CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
               mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclickdn(posx,posy):
               mouseEvent(kCGEventLeftMouseDown, posx,posy);
    def mouseclickup(posx,posy):
               mouseEvent(kCGEventLeftMouseUp, posx,posy);
    def mousedrag(posx,posy):
               mouseEvent(kCGEventLeftMouseDragged, posx,posy);
    ourEvent = CGEventCreate(None);
    # Save current mouse position
    currentpos=CGEventGetLocation(ourEvent);
    # move mouse to upper left of screen
    mouseclickdn(40, 60);
    # drag icon to new location
    mousedrag(60, 300);
    # release mouse
    mouseclickup(60, 300);
    # necessary delay
    time.sleep(1);
    # return mouse to start positon
    mouseclickdn(int(currentpos.x),int(currentpos.y));
    For keystokes in AppleScript (which can be added to Automator with the Run Applescript Action) see: http://dougscripts.com/itunes/itinfo/keycodes.php

  • How to send a file from FTP to external server

    My requirement is to send a file from FTP to D3(External) server.
    Now I am able to store the file in Appln server.
    I want to send the file created by the program thru FTP to D3 server.
    I know the username,Password,HostID,RFC destination details.
    How to send the file from FTP to D3.
    If u have any program,Plz send it...
    I dont want the function modules name...I want the example code ....
    Thanks in advance.

    Hi Sumi,
    You could do it so that you create a .bat or .cmd script to your server which does your ftp transfer.
    To do this you must use sm69 to create a external operating system command which you can call from FM SXPG_COMMAND_EXECUTE. To SXPG_COMMAND_EXECUTE you the file you need to transfer as a parameter.
    What happens is that your abap program passes the file to windows batch script (.bat .cmd) which will then do the transfer for you.
    Here's a sample of ftp-script for windows:
    echo open IP_ADDRESS_TO_YOUR_SERVER > c:zftp_transfer.ftp
    echo USERNAME>> c:zftp_transfer.ftp
    echo PASSWORD>> c:zftp_transfer.ftp
    echo put YOUR_FILE>> c:zftp_transfer.ftp
    echo quit>> c:zftp_transfer.ftp
    ftp -s:c:zftp_transfer.ftp
    also take a look here for more details:
    http://support.microsoft.com/?kbid=96269
    Ok, this might be a bit trivial but if your server is unix/aix etc.. Instead of using batch script you must do a shell script.
    Regards,
    Ville

  • How can I open a second window in iTunes?

    When I see some albums in the the iTunes Store I want to check whether I have some of the songs already. The Search function in the Store only refers to the store and not to my Library. So how can I open a second window in iTunes (one with the Store and one with my Library) to make it easier to compare?
    Thanks

    My understanding it that was removed from iTunes recently (I still run iTunes 7.5 from 2007), so no, not unless you downgrade iTunes (which is not easy).  You can send feedback to Apple about reinstating it but I have yet to see Apple reinstate something that appeared to have been deliberately removed from its software, despite vociferous complaints on this forum.
    http://www.apple.com/feedback/itunesapp.html

  • How can i use messages on windows

    im trying to use my imessage on my laptop is there like a software that doesnt require jailbreak to send messages on the laptop?

    ryan10132 wrote:
    how can I use messages on windows
    You can't.

  • How to get black text in window title

    I have difficulty distinguishing between active windows and inactive windows because the title text for both is a shade of gray. How can I theme OS X Lion to use black text  scrollbar, and controls for active windows; gray for inactive windows?
    I am tired of having to click on a window to ensure that it is active.

    Ha, I had the graphite theme, so they were gray. While they were darker than an inactive window, they still didn't call attention to themselves. I've switched to blue and now they're in color. Not sure why they are called "blue" and "graphite" as the only difference I notice is the color buttons, none of which are blue, for blue and the gray buttons for graphite. I still don't usually look over in that direction; I'm looking at the title to see if its the window I'm interested it. Still, that gets a helpful.
    Still, I'd really like black text as I find gray text harder to read. And the back/forward buttons in Firefox don't change enough between active and inactive. I'd like that to be really black. (I'm told that OS X theming interferes with being able to change that; not sure if it's true.)
    As for the active one usually being in front, that's assuming that the active one is taking up a majority of the real estate. I often have two windows side-by-side. Further, stickies don't have the three buttons, so it's no help when they're active (and there's a bug - which I've reported - that sometimes makes them inadvertently active).

  • How to send IP pacekts by LabVIEW RT

    In a project,I use PXT RT controler and cRIO , need send IP packets to communicate with other PCs.
    I can use raw socket to send IP packets on the Windows,how to send IP pacekts on the Pharlap and Vxworks by by LabVIEW RT?
    There is somebody can help me ,thank you very much.

    Different methods of communicating between a VI on a Real-time target (RT PXI, cRIO) and a VI on Windows are outlined in Real-Time VI to Host VI Communication Methods. One of them is TCP communication, which sounds like the solution you're looking for (there are examples in the Example Finder). However, if you can get away with using shared variables, I'd recommend using them out of simplicity (you can flatten and unflatten to/from string or variant data types if necessary).
    Good luck!
    Misha

  • How to send a form in DW 7?

    Hi! I'm from Spain and I'd like to be understanded if possible. I've got Dreamweaver MX 7. I'd like to know how to send directly the form:
    I design a form, I put a text box with "name", "e-mail" and "comment" for example and the button "send". If I test it, when I press send, the Outlook (I've got windows XP) is opened with the information.written in the form.
    Can I send the form without opening the Outlook?
    It is possible to do it with HTML language?
    Where do I have to write the script?
    If it isn't possible in HTML, how do I do it in PHP?

    http://www.cmiwebstudio.com/adobe_extensions/dreamweaver_easy_php_mailer.php
    http://www.cmiwebstudio.com/adobe_extensions/dreamweaver_easy_php_mailer_pear.php
    these extensions make it incredibly easy to do this very task.  determine first how your server email is being handled... through phps built in mail function, or does it require smtp authentication to relay mail.

Maybe you are looking for

  • Transport target for business system not found in System Landscape Director

    Folks, We have new installed new PI 7.1 system and importing interfaces from the OLD XI 3.0 system in to new PID 7.1 system. We are getting following error when we try to import an interfaces in to new PID system: Import failed because of business sy

  • HT201415 I inserted a working sim card but iPad(2) says "no SIM" - cellular data setting greyed out

    I inserted a working SIM card into my iPad 2. It picked up the network but later gave a message saying "No SIM". The Cellular Data control option is greyed out so I cannot get in to this function. I have tried removing the SIM and re-inserting as wel

  • Problem Running SqlDeveloper RedHat Linux AS4

    hi I have downloaded latest sqldeveloper release rpm for linux it installs successfully in /opt/sqldeveloper folder but when i try to run sqldeveloper it did not run and shows messages as # sh sqldeveloper.sh Oracle SQL Developer Copyright (c) 2006,

  • Iweb SEO tool or iweb valet

    Which is the best iweb SEO tool or iweb valet? or is there a alternative to these? I have used iweb SEO tool, itweak, RAGE Sitemap Automator, and upload my site http://www.southfarm.co.uk/home.html with Transmit. It is a pain when I have a small upda

  • Email output using Standard SAP and outlook

    Can anyone provide detailed configuration tips for output determination which includes defining communication strategy, output types, output procedure and condition records? I am trying to set up email generation to customers based on billing documen