How to make Windows 8 tablet open the on-screen-keyboard when an input field gets focus?

假装没事ソ 提交于 2019-12-12 04:47:21

问题


I am developing an app for a Windows 8.1 tablet (using Java & eclipse RCP).

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)

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.

The OSK is started as follows

cmd /c c:WINDOWS/system32/osk.exe

Perhaps there is another way to start it so that the input field does not loose focus.

UPDATE

I managed to open the keyboard programmatically using

Runtime.getRuntime().exec(path + "tabtip.exe")

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?


回答1:


namespace Windows.ApplicationModel.Search.SearchPane has a property called ShowOnKeyboardInput.

However, this is used for searching via Search charm.




回答2:


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());
            }
        }
    });

NOTE

taskkill tabtip.exe only works when run as Administrator on Windows 8. Starting via cmd does not need these privileges. Why ?!? :-(



来源:https://stackoverflow.com/questions/25761421/how-to-make-windows-8-tablet-open-the-on-screen-keyboard-when-an-input-field-get

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!