输入字段获得焦点时,如何使Windows 8平板电脑打开屏幕键盘? [英] How to make Windows 8 tablet open the on-screen-keyboard when an input field gets focus?
问题描述
我正在为Windows 8.1平板电脑开发一个应用程序(使用Java&eclipse RCP).
I am developing an app for a Windows 8.1 tablet (using Java & eclipse RCP).
我希望Windows在文本字段获得焦点时自动打开OSK,并在焦点丢失时再次关闭它.此功能适用于某些内置Windows功能,例如搜索(从屏幕右侧扫入并显示搜索字段)
I would like Windows to automatically open the OSK when a text field receives focus and to close it again when the focus is lost. This works for some of the built-in windows functions such as search (swipe in from the right side of the screen and the search field appears)
我试图以编程方式打开OSK,但无法按预期方式工作. OSK已启动,但在一个窗口中,该窗口将焦点从输入字段移开,因此,键入的字符无法到达输入.
I have tried to open OSK programmatically but it does not work as expected. The OSK is started but in a window which removes the focus from the input field and, therefore, the characters typed to not reach the input.
OSK如下启动
cmd /c c:WINDOWS/system32/osk.exe
也许还有另一种启动方式,以使输入字段不会失去焦点.
Perhaps there is another way to start it so that the input field does not loose focus.
更新
我设法通过编程方式打开了键盘
I managed to open the keyboard programmatically using
Runtime.getRuntime().exec(path + "tabtip.exe")
但仅在之后,我以管理员身份运行该应用程序.为什么我可以从命令行运行tabtip但不能从我的应用程序启动它?
but only after I ran the app as Administrator. Why can I run tabtip from the command line but not start it from my app?
推荐答案
这是我的解决方案,似乎可以正常工作.我曾希望Windows 8能够自动执行此操作,但我找不到办法.
This is my solution which seems to work ok. I had hoped that Windows 8 might be able to do this automatically but I couldn't find a way.
text.addFocusListener(new FocusListener()
{
@Override
public void focusLost(FocusEvent arg0)
{
LogUtil.logInfo("Closing OSK");
try
{
if(Settings.getBoolean(Settings.OSK_USETABTIP)) {
Runtime.getRuntime().exec("cmd /c taskkill /IM tabtip.exe");
} else {
Runtime.getRuntime().exec("cmd /c taskkill /IM osk.exe");
}
}
catch (IOException e)
{
LogUtil.logError(e.toString());
}
}
@Override
public void focusGained(FocusEvent arg0)
{
try
{
String sysroot = System.getenv("SystemRoot");
if(Settings.getBoolean(Settings.OSK_USETABTIP)) {
LogUtil.logInfo("Opening TabTip");
ProcessBuilder pb = new ProcessBuilder("C:/pathtotabtip/tabtip.exe");
pb.start();
} else {
LogUtil.logInfo("Opening OSK");
ProcessBuilder pb = new ProcessBuilder(sysroot + "/system32/osk.exe");
pb.start();
}
}
catch (Exception e)
{
LogUtil.logError(e.toString());
}
}
});
注意
taskkill tabtip.exe
仅在Windows 8上以管理员身份运行时才有效.通过cmd
启动不需要这些特权.为什么 ?!? :-(
taskkill tabtip.exe
only works when run as Administrator on Windows 8. Starting via cmd
does not need these privileges. Why ?!? :-(
这篇关于输入字段获得焦点时,如何使Windows 8平板电脑打开屏幕键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!