2

I need to open the Windows's virtual keyboard from my application, which will be deployed using Eclipse RCP on the windows 32 bit platform (i.e. win32 JRE).

Following the answers to the post open the Windows virtual keyboard in a Java program , the applications does so correctly on a 32 bit Windows OS, but refuses to work on a 64 bits Windows OS.

The solution I am using is the following ones:

//          String sysroot = System.getenv("SystemRoot"); //$NON-NLS-1$
//          Runtime.getRuntime().exec("cmd.exe /c "+sysroot + "\\system32\\osk.exe /n"); //$NON-NLS-1$ //$NON-NLS-2$
            Runtime.getRuntime().exec("osk");

Is there a way to fix this without using a 64 bit deploy? (which I can't create, as long as I am using a library that does not support this environment).

Thanks

Community
  • 1
  • 1
  • 1
    If your Java app is compiled/run in 32-bit mode using 32-bit mode JVM, you can't run a process that call a 64-bit version of the executable. Let say, Windows XP 32-bit hence its OSK.EXE version is 32-bit; then your Java app can execute the process since it matches using 32-bit mode JVM. Now, let say Windows 7 64-bit hence its OSK.exe version is 64-bit, but your Java app is compiled/run in 32-bit mode using 32-bit mode JVM, then your app will not run the process as it doesn't match. [see link](http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/e9252bb7-1df0-4826-880f-ad0a636a18cd/) – ee. Dec 01 '11 at 02:39
  • Thanks for your help ee. , that's the hypothesis I had. If I find a workaround I will post it in this post – Josep Rodríguez López Dec 01 '11 at 08:46
  • This is a total hack, but what if you wrote a tiny native wrapper that just called the executable, and made that wrapper 32-bit? You could then execute the wrapper from your Java code. The wrapper could be as simple as `system("osk");` in C/C++. – aardvarkk Dec 12 '11 at 15:25
  • I'll try to use a .bat file using this, just to avoid the dependency java - c++ first, but I'll try to do what you said. Thanks – Josep Rodríguez López Dec 12 '11 at 16:01
  • calling a bat file can be a nice idea, interested to know – Kowser Dec 13 '11 at 15:08
  • The bat file didn't fix the issue... I'll try to compile a c++ program and post the results here. – Josep Rodríguez López Dec 14 '11 at 09:16
  • Unless it's absolutely necessary to use the Windows on-screen keyboard, I would create my own on-screen keyboard so that my program would be cross-platform. – Jeffrey Dec 19 '11 at 04:31

3 Answers3

0

Try this code. not sure it will work. but worth a try.

Desktop desktop = null;
if (Desktop.isDesktopSupported()) 
{
    desktop = Desktop.getDesktop();
}
String sysroot = System.getenv("SystemRoot");
desktop.open(new File(sysroot+"/system32/osk.exe"));

I am new to this Desktop class, and i would like to know if the class does the trick ;)

Naveen Babu
  • 1,584
  • 1
  • 14
  • 35
  • Desktop.open() is used to open the application associated with a file (e.g. a word processor, text editor and so on). I doubt that you can run an executable with it (but haven't tried) –  Dec 14 '11 at 11:28
  • Actually i wanted to do the same- open the executable. since the Desktop.open() used to open with windows configuration(ie file type referance), i was hoping the 64-bit issue wont come into the picture in that case. i ran this code. and it works on my machine.. but i didnt try with different bit-referance. ie: 64-bit windows and 32 bit jre. – Naveen Babu Dec 14 '11 at 11:37
0

No. You won't be able to use the 64-bit library from a 32-bit Java app and/or a 32-bit OS. You'll have to deploy your app x64.

one.beat.consumer
  • 9,414
  • 11
  • 55
  • 98
0

this is my workaround:

FileOutputStream fileOutputStream = new FileOutputStream(new File("C:/TEMP/RUN.BAT"));

        String file = "START C:/Windows/System32/osk.exe" + '\n'
                + "EXIT";
        fileOutputStream.write(file.getBytes());
        fileOutputStream.close();
        Runtime.getRuntime().exec("CMD /C START C:/TEMP/RUN.bat");
        Runtime.getRuntime().exec("CMD /C DEL C:/TEMP/RUN.bat");
user1097489
  • 129
  • 5