Sending keystrokes from a C# application to a Java application - strange behaviour?

I'm trying to send keystrokes from my C# program to a Java application

The code for sendig keys is:

private void SendKeysToWindow(string WindowName, string KeysToSend) { IntPtr hWnd = FindWindow(null, WindowName); ShowWindowAsync(hWnd, SW_SHOWNORMAL); SetForegroundWindow(hWnd); SendKeys.Send(KeysToSend); }

This code works fine with all programs, except with the Java application that I'm tyring to control.

For example, if I create a button with the folowing code:

SendKeysToWindow("Java application window name", "{F2}"); SendKeysToWindow("Popoup window name", "123");

This sends an F2 to the main program window, where another window pops up, and the second SendKeysToWindow command sends the "123" to that window. This is how it is expected to work, and this is the case with all other programs.

However, when I send these commands to the Java program, the following happens: the first SendKeysToWindow command is executed fine (the popup window appears), but it does not send the "123" to that window.

If is press the button again, the "123" is sent to the popup window, and it opens another popoup window.

If I create two separate buttons for the two SendKeysToWindow command, and press them one after another, both commands execute fine.

What can be the probem?

Thanks for the help in advanvce, it's really driving me crazy.

P.S.: I'm a beginner in C#, so please keep the answer simple.

-------------Problems Reply------------

After some trial and error, the following code seems to work fine:

private void SendKeysToWindow(string WindowName, string KeysToSend)
{
IntPtr hWnd = FindWindow(null, WindowName);
ShowWindow(hWnd, SW_SHOWNORMAL);
SetForegroundWindow(hWnd);
Thread.Sleep(50);
SendKeys.SendWait(KeysToSend);
}

It sounds like there might just be a delay between sending {f2} and the Java application opening the popup window.

Have you tried checking whether FindWindow succeeds or fails?

Category:c# Views:0 Time:2010-01-10

Related post

  • How to send structure from a C application to an Java Application with UDP 2012-04-12

    I actually want to send a structure over UDP from a C application to a java application. The struct looking like that : typedef struct { type1 liste1; type2 liste2; type3 liste3; type4 liste4; }liste; And type1,2,3,4 are also structure which include

  • Launch a java application from another java application 2010-03-05

    I'm doing a Java Record/Replay tool and I need to launch Java applications from my main Java app. I need access to the EventDispatchThread in order to intercept the events and record them, so I'm launching the application through reflection with (cod

  • Different Versions of an application in same java application server 2010-05-01

    We are utilizing citrix netscalar with more than 20 glassfish java application servers. Unfortunately we have to remove previous application before deploying a new version of it since we have same context for these two different application. This err

  • PHP web application calling a Java application 2011-02-04

    I need to develop a web application using PHP and the Apache web server. The application should call an external Java-based application which is stored in the host computer and pass the user's input value to this application which will analyse it and

  • How to use a NetBeans Platform application from another Java application 2010-03-14

    Imagine you have a NB Platform application and you would like to use that application via some other app that you've created. In essence, how can you learn how to start an application if you don't want to use the NB Platform or IDE. You'd somehow nee

  • How to send Keystrokes to an windows application from web application 2014-07-12

    Hi All, How can i send keystrokes from the web application.I have found may solutions and applied but it's not working.Mainly i need to say that an opened powerpoint application pops an message box like update links i need to send keystroke to the me

  • sending keys to a Java application's textbox from C# 2011-01-26

    I am trying to make an automation application that basically send some keys to a textbox in a java application and, if possible, based on the text that is in the textbox. Also I would like to select a certain option for a combobox. Can someone direct

  • Transferring file using sockets from C++ application to Java application 2011-02-23

    I'm trying to transfer a file using sockets from a C++ application to a Java application. I wrote this simple code in C++ to send the file: int main() { int sock; struct sockaddr_in sa; char* memblock; /* Create socket on which to send. */ sock = soc

  • What is the best way to safely end a java application with running RabbitMQ consumers 2011-07-14

    We have a standalone java application doing some background processing on a Debian machine. The jobs it has to handle are send through RabbitMQ messages. When the java application needs to be upgraded we need to stop it (kill it). But we have to be s

  • How to run iReport-nb 3.x.x from whithin another java application? 2009-05-12

    I'd like to start using iReport (netbeans edition) and replace the good old classic iReport 3.0.x. Seems like the classic iReport won't be improved anymore and abandoned at some point. The point is that I need to start iReport from another java appli

  • Have an external java application by notified of changes to Entity EJBs in JBoss AS 2010-06-05

    I'm trying to connect an external application to a JBoss AS container. The external application is a Java application that is currently being notified of changes to database entities through a JMS topic. I've added an EntityLifecycleListener class to

  • J2EE and Standard Java Application Log4j.properties 2010-11-04

    I have a project folder with merged J2ee application and standard java application. I am having trouble with configuring the Log4j.properties. I want to have separate log files 1 for my web application and another 1 for my standard application. I hav

  • how to get mouse position of a Java application? 2011-02-26

    documentDOM.addEventListener("click", new EventListener() { public void handleEvent(Event evt) { if (evt.getType().equals("click")) { System.out.println("hello"); MouseEvent mouseIvent = (MouseEvent) evt; int screenX = mouseIvent.getXOnScreen(); int

  • Launch Java class from another Java application 2012-01-27

    Is there a way to launch a java class (and pass it a classpath and libary path) from within a Java application with out using Runtime.exec? I have seen: Launch a java application from another java application but need to be able to pass a CLASSPATH a

  • Programmatically send keystrokes to GLUT application 2008-10-12

    I have an OpenGL/GLUT program running on my linux machine that views a 3D model from various angles and can take screenshots, and everything is controlled from the keyboard. I want to write a script that moves around the model in a particular way, ta

  • Simple Application for sending Keystroke in VB.NET 2012-03-20

    I have an issue regarding Sendkeys Class, as i want to use this class in order to send some keystroke to the active application. As a first step i want to test the {Enter} keystroke, so in order to achieve that i made a simple application in vb.net 2

  • Send keystrokes to other applications 2014-03-05

    I'm trying to write a program in C# that lets me send a keystroke to another program that's open but is not in the foreground. The purpose of the program is to let me start recording gameplay footage from my Xbox 360 using TotalMedia Extreme while al

  • iPhone/Android: How to Send Keystrokes To Laptop Over Wifi? 2010-04-09

    How can I best implement a system for send keystrokes/commands via an iPhone and/or Droid to a desktop or laptop computer via WiFi or bluetooth? There are apps for VLC, Keynote and other applications that do this, so I know it's possible but don't kn

  • Send Keystrokes to a program even if its in background using c# 2011-01-13

    I wanna send key stroke to a program even if it is running in background. But I can do this only for NOTEPAD like this, [DllImport("user32.dll")] protected static extern byte VkKeyScan(char ch); [DllImport("user32.dll", SetLastError = true)] protecte

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.203 (s). 11 q(s)