0

I'm new to autoit and trying to integrate it with a java app. I can't make it send enter or tab or ctrl, it sends only plain text.

The code is this:

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    String jacobDllVersionToUse;
        if (jvmBitVersion().contains("32")){
            jacobDllVersionToUse = "jacob-1.18-M2-x86.dll";
        }
        else {
            jacobDllVersionToUse = "jacob-1.18-M2-x64.dll";
        }
     try{ 
    File file = new File("lib", jacobDllVersionToUse);
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

    AutoItX x = new AutoItX();
    x.run("Skype", "C:/Program Files (x86)/Skype/Phone", AutoItX.SW_SHOW);
    x.winActivate("Skype");
    x.winWaitActive("Skype");
    x.sleep(2000);
    x.send("{TAB}!n" );
     }catch(Exception e){

   } 
}                                        

I already tried:

  • x.controlSend("Window Title","text","","{ENTER}",false);
  • x.send("{TAB}!n" );
  • x.send("{TAB}n" );
spenibus
  • 4,339
  • 11
  • 26
  • 35
Tehnic
  • 29
  • 7
  • Where's your AutoIt code? A small functioning method would be nice. What is `"AutoItX"`? – Hovercraft Full Of Eels Sep 09 '15 at 14:28
  • Ah, you're using AutoItX4Java, aren't you? As a side note, you must take care to run all AutoIt code within a background thread, else it could freeze your Swing GUI. – Hovercraft Full Of Eels Sep 09 '15 at 14:30
  • Also, what is the overall goal of this code? If your desire is to push text into a Swing text component, then there may be better ways to do this. – Hovercraft Full Of Eels Sep 09 '15 at 14:38
  • Yes i use AutoItX4Java, and i know the problem with the freezes and im working to fix that but now i have to fix the autoit script, thy for the advice – Tehnic Sep 09 '15 at 14:42
  • The goal is to auto login on skype presing only a button this is a part of a app for auto login on some sites and some apps and it must send thins like ENTER, TAB, ALT – Tehnic Sep 09 '15 at 14:45
  • I would do the complete login stuff in autoit and just call/start the autoit script from your java program. – Xenobiologist Sep 09 '15 at 15:53
  • i tink that selenium is more ok for web pages i need autoit only for windows apps – Tehnic Sep 09 '15 at 16:32

2 Answers2

2

It works with true or false thy to Milos for giving me the solution

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String sql="select * from app_1 where id_user_main=?";  
    String jacobDllVersionToUse;
        if (jvmBitVersion().contains("32")){
            jacobDllVersionToUse = "jacob-1.18-M2-x86.dll";
        }
        else {
            jacobDllVersionToUse = "jacob-1.18-M2-x64.dll";
        }
     try{ 
    File file = new File("lib", jacobDllVersionToUse);
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());
    AutoItX x = new AutoItX();
    x.run("Skype", "C:/Program Files (x86)/Skype/Phone", AutoItX.SW_SHOW);
    x.winWait("Skype");
    x.winActivate("Skype");
    x.winWaitActive("Skype");
    x.sleep(2000);
    x.send("{TAB}!n", false );

     }catch(Exception e){

   } 
}                                        

Thy all for the help

Tehnic
  • 29
  • 7
0

You are missing WinWait.

Try this

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    String jacobDllVersionToUse;
        if (jvmBitVersion().contains("32")){
            jacobDllVersionToUse = "jacob-1.18-M2-x86.dll";
        }
        else {
            jacobDllVersionToUse = "jacob-1.18-M2-x64.dll";
        }
     try{ 
    File file = new File("lib", jacobDllVersionToUse);
    System.setProperty(LibraryLoader.JACOB_DLL_PATH, file.getAbsolutePath());

    AutoItX x = new AutoItX();
    x.run("Skype", "C:/Program Files (x86)/Skype/Phone", AutoItX.SW_SHOW);
    x.winWait("Skype");
    x.winActivate("Skype");
    x.winWaitActive("Skype");
    x.sleep(2000);
    x.send("{TAB}!n", false );
     }catch(Exception e){

   } 
}     
Milos
  • 2,927
  • 1
  • 15
  • 27