diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index 9ecaf7f..9b40e4d 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,6 @@ eclipse.preferences.version=1 encoding//Demo/AutoRestart.py=utf-8 +encoding//Demo/CallVirtualKeyboard.py=utf-8 encoding//Demo/CircleLine.py=utf-8 encoding//Demo/EmbedWindow.py=utf-8 encoding//Demo/FacePoints.py=utf-8 diff --git a/Demo/CallVirtualKeyboard.py b/Demo/CallVirtualKeyboard.py new file mode 100644 index 0000000..b44af51 --- /dev/null +++ b/Demo/CallVirtualKeyboard.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +Created on 2019年5月22日 +@author: Irony +@site: https://pyqt5.com https://github.com/892768447 +@email: 892768447@qq.com +@file: Demo.CallVirtualKeyboard +@description: 调用系统虚拟键盘 +""" +import glob + +from PyQt5.QtCore import QProcess, QSysInfo +from PyQt5.QtWidgets import QWidget, QTextEdit, QVBoxLayout, QPushButton + + +__Author__ = 'Irony' +__Copyright__ = 'Copyright (c) 2019 Irony' +__Version__ = 1.0 + + +class Window(QWidget): + + def __init__(self, *args, **kwargs): + super(Window, self).__init__(*args, **kwargs) + layout = QVBoxLayout(self) + self.resultEdit = QTextEdit(self) + self.resultEdit.setReadOnly(True) + layout.addWidget(self.resultEdit) + layout.addWidget(QPushButton( + '打开虚拟键盘', self, clicked=self._onOpenKeyboard)) + + def _onOpenKeyboard(self): + kernelType = QSysInfo.kernelType() + if kernelType == 'winnt': + try: + path = glob.glob( + r'C:\Windows\WinSxS\amd64_microsoft-windows-osk_*\osk.exe')[0] + ret = QProcess.startDetached(path) + self.resultEdit.append('start 64 osk: %s' % ret) + except Exception as e: + self.resultEdit.append('start osk error: %s' % e) + try: + # 32位程序调用64位操作系统下的程序会被重定向到SysWOW64目录 + # 可通过`Wow64DisableWow64FsRedirection`和`Wow64RevertWow64FsRedirection`控制 + ret = QProcess.startDetached(r'C:\Windows\system32\osk.exe') + self.resultEdit.append('start 32 osk: %s' % ret) + except Exception as e: + self.resultEdit.append('start osk error: %s' % e) + elif kernelType == 'darwin': + pass +# elif kernelType=='linux': + else: + ret = QProcess.startDetached('florence') + self.resultEdit.append('start florence: %s' % ret) + ret = QProcess.startDetached('onboard') + self.resultEdit.append('start onboard: %s' % ret) + ret = QProcess.startDetached('kvkbd') + self.resultEdit.append('start kvkbd: %s' % ret) + + +if __name__ == '__main__': + import sys + from PyQt5.QtWidgets import QApplication + app = QApplication(sys.argv) + w = Window() + w.show() + sys.exit(app.exec_()) diff --git a/Demo/README.md b/Demo/README.md index 980ebdf..cab8264 100644 --- a/Demo/README.md +++ b/Demo/README.md @@ -21,6 +21,7 @@ - [无边框圆角对话框](#18无边框圆角对话框) - [调整窗口显示边框](#19调整窗口显示边框) - [判断信号是否连接](#20判断信号是否连接) + - [调用虚拟键盘](#21调用虚拟键盘) ## 1、重启窗口Widget [运行 RestartWindow.py](RestartWindow.py) @@ -204,4 +205,13 @@ PyQt 结合 Opencv 进行人脸检测; 通过 `isSignalConnected` 判断是否连接 -![IsSignalConnected](ScreenShot/IsSignalConnected.png) \ No newline at end of file +![IsSignalConnected](ScreenShot/IsSignalConnected.png) + +## 21、调用虚拟键盘 +[运行 CallVirtualKeyboard.py](CallVirtualKeyboard.py) + +1. Windows上调用的是`osk.exe` +2. Linux上调用的是`florence`,`onboard`,`kvkbd`,这三种屏幕键盘需要自行安装 + +![CallVirtualKeyboard1](ScreenShot/CallVirtualKeyboard1.png) +![CallVirtualKeyboard2](ScreenShot/CallVirtualKeyboard2.png) \ No newline at end of file diff --git a/Demo/ScreenShot/CallVirtualKeyboard1.png b/Demo/ScreenShot/CallVirtualKeyboard1.png new file mode 100644 index 0000000..90bb7bf Binary files /dev/null and b/Demo/ScreenShot/CallVirtualKeyboard1.png differ diff --git a/Demo/ScreenShot/CallVirtualKeyboard2.png b/Demo/ScreenShot/CallVirtualKeyboard2.png new file mode 100644 index 0000000..b3556cf Binary files /dev/null and b/Demo/ScreenShot/CallVirtualKeyboard2.png differ diff --git a/README.md b/README.md index c74d778..728aeb4 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站 - [使用Threading](Demo/QtThreading.py) - [背景连线动画](Demo/CircleLine.py) - [判断信号是否连接](Demo/IsSignalConnected.py) + - [调用虚拟键盘](Demo/CallVirtualKeyboard.py) # QQ群