1

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 me to the right path? some code, an example, anything...

thank you, denis

denis
  • 11
  • 1

2 Answers2

2

hello i think you're looking something like this "winApiHelper" is a class made by me that help me to implement Win Api's methods, take a look here http://msdn.microsoft.com/en-us/library/ms633539(v=vs.85).aspx

private void SendKeys()
//String sText , String sWindow
//alternate you can have a parameters 
{
    string stab = "{TAB}";
    string skey = rtFilename.Text.Trim();
    int iHandle = winApiHelper.FindWindow(null, cboWindows.Text.Trim());
    winApiHelper.SetForegroundWindow(iHandle);                         
    System.Windows.Forms.SendKeys.Send(skey.Trim() + stab.ToString().Trim());
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Erlan
  • 21
  • 2
1

First, java.awt.Robot allows you to emulate keyboard and mouse events. Unfortunately it works in absolute screen coordinates. Right now java does not have API that allows to access windows beyond current application.

But if you can find the absolute location of text box where you wish to write "hello, world" you can do it using Robot.

If you cannot get absolute coordinates you have to use other tools like JNI or JNA. Please see the following post for details: Windows: how to get a list of all visible windows?

Good luck1

Community
  • 1
  • 1
AlexR
  • 114,158
  • 16
  • 130
  • 208
  • hi alexr, thank you for the info but I was looking for code in C#, I have a C# application that I want to send keys from to a Java app. To be more clear, I have a C# app (bot) from which I want to send keys to a Java based app when certain text is written in the Java app text box... thanks, denis – denisr Jan 27 '11 at 14:20