Java-调用屏幕键盘 [英] Java - invoke on-screen keyboard

查看:532
本文介绍了Java-调用屏幕键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理的应用程序将在Windows 7上运行.它将用于通过触摸屏输入一些信息.每当提示用户提供信息时,我都需要在屏幕上弹出键盘.我的问题是,应该从头开始创建键盘类,还是应该使用Windows 7内置屏幕键盘,以及如何在Java应用程序中调用它?谢谢

The application I am working on will run on Windows 7. It will be used to input some information via touchscreen. I need to have an on-screen keyboard popup whenever user is prompted for information. My question is, should I create a keyboard class from scratch or should I use the Windows 7 built-in on-screen keyboard and how would I invoke it in my Java application? Thank you

推荐答案

我刚刚使用屏幕键盘玩过,发现很简单.您只需要使用Runtime.exec()ProcessBuilder来调用它.然后,如果您的应用程序失去焦点,则将其带回应用程序,而活动元素必须是当前可编辑元素(文本字段,文本区域等).现在,当用户在虚拟键盘上键入字符时,字符将被写入您的应用程序.

I have just played with on-screen keyboard and saw that it is easy. You just have to invoke it using either Runtime.exec() or ProcessBuilder. Then if your application lost focus take it back to the application, while the active element must be the current editable element (text field, text area etc). Now when user is typing on the virtual keyboard the characters are being written to your application.

从Java执行osk.exe会有一些困难.它抛出IOException: java.io.IOException: Cannot run program "C:\Windows\System32\osk.exe": CreateProcess error=740, The requested operation requires elevation

There are some difficulties to execute osk.exe from java. It throws IOException: java.io.IOException: Cannot run program "C:\Windows\System32\osk.exe": CreateProcess error=740, The requested operation requires elevation

技巧是通过命令外壳(cmd)运行命令:

The trick is to run the command via command shell (cmd):

Runtime.getRuntime().exec("cmd /c C:\\Windows\\System32\\osk.exe");

这条线在我的机器上工作正常.

This line works fine on my machine.

这篇关于Java-调用屏幕键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆