控制屏幕键盘python

时间:2015-10-06 22:16:04

标签: python windows subprocess on-screen-keyboard

我有一个触摸屏应用程序,我正在尝试在应用程序需要输入时启动屏幕键盘并关闭键盘以释放屏幕空间。

下面的代码将启动键盘,但是当我尝试终止()进程时,子进程返回0(成功),但应用程序保持打开状态。

如何关闭/最小化键盘以释放屏幕空间?

import subprocess
import platform

class keyboard_mixin(object):
    def __init__(self):
        self.keyboard_process = None

    def show(self):
        if platform.system() == "Linux":
            try:
                cmd_path = "xvkbd"
                self.keyboard_process = subprocess.Popen([cmd_path])
                return
            except OSError:
                pass

        elif platform.system() == "Windows":
            try:
                cmd_path = "C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe"
                self.keyboard_process = subprocess.Popen([cmd_path], shell=True)
                return
            except OSError:
                pass

            try:
                cmd_path = "C:\\WINDOWS\\system32\\osk.exe"
                self.keyboard_process = subprocess.Popen([cmd_path], shell=True)
                return
            except OSError:
                pass

    def hide(self):
        # TODO: This does not close on windows platform
        if self.keyboard_process is not None:
            self.keyboard_process.terminate()
            self.keyboard_process = None

if __name__ == '__main__':
    osk = keyboard_mixin()
    osk.show()
    osk.hide()

0 个答案:

没有答案