Pregunta

I am working on this login page that has 2 textfield and a button. Whenever I click on the first textfield, the On-Screen Keyboard (osk.exe) will pop up, but when I click on the second textfield, the On-Screen keyboard doesn't seem to focus on the second textfield, meaning that I cannot type anything on the second textfield, so what I tried to do was stop osk.exe process and start it up again when I select the second textfield, but osk doesn't seem to pop out on the first click, I have to click the second time to pop it out, so it means each time I click on the textfield, it will pop out and close OSK turn by turn, can anyone help me please? two of my textfield has the following onClick method in JavaFx Scene Builder:

public void osk (){

    try
    {
        killProcess();
        Runtime.getRuntime().exec("c:\\Temp\\osk.exe");

    }
    catch ( Exception ex )
    {
        ex.printStackTrace();
    }

                    }



 public static void killProcess() throws Exception {

    Runtime rt = Runtime.getRuntime();
    rt.exec("taskkill " + "osk.exe");

    Runtime.getRuntime().exec( "taskkill /IM " + "osk.exe" );

 }

edit: I added more description, sorry for not including it earlier.

¿Fue útil?

Solución 2

I've managed to solve it myself, it turns out that I have to delay the thread for a second, else the OSK would not have the opportunity to pop up, and thus killed. Correct me if I am wrong

 try
    {

     killProcess();


     try {
              Thread.sleep(1000);
         }    catch(InterruptedException ex) 

         {
              Thread.currentThread().interrupt();
         }



     Runtime.getRuntime().exec("c:\\Temp\\osk.exe");

    }
    catch ( Exception ex )
    {
        ex.printStackTrace();
    }

                    }

Otros consejos

taskkill is a windows cmd command. I think you could try replace rt.exec("taskkill " + "osk.exe"); by rt.exec("cmd.exe /c taskkill " + "osk.exe");

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top