调用虚拟键盘
This commit is contained in:
parent
7dc252a56e
commit
676b0a4139
6 changed files with 82 additions and 1 deletions
|
@ -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
|
||||
|
|
69
Demo/CallVirtualKeyboard.py
Normal file
69
Demo/CallVirtualKeyboard.py
Normal file
|
@ -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_())
|
|
@ -21,6 +21,7 @@
|
|||
- [无边框圆角对话框](#18无边框圆角对话框)
|
||||
- [调整窗口显示边框](#19调整窗口显示边框)
|
||||
- [判断信号是否连接](#20判断信号是否连接)
|
||||
- [调用虚拟键盘](#21调用虚拟键盘)
|
||||
|
||||
## 1、重启窗口Widget
|
||||
[运行 RestartWindow.py](RestartWindow.py)
|
||||
|
@ -205,3 +206,12 @@ PyQt 结合 Opencv 进行人脸检测;
|
|||
通过 `isSignalConnected` 判断是否连接
|
||||
|
||||
![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)
|
BIN
Demo/ScreenShot/CallVirtualKeyboard1.png
Normal file
BIN
Demo/ScreenShot/CallVirtualKeyboard1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
BIN
Demo/ScreenShot/CallVirtualKeyboard2.png
Normal file
BIN
Demo/ScreenShot/CallVirtualKeyboard2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 164 KiB |
|
@ -201,6 +201,7 @@ https://pyqt5.com 社区是专门针对PyQt5学习和提升开设的博客网站
|
|||
- [使用Threading](Demo/QtThreading.py)
|
||||
- [背景连线动画](Demo/CircleLine.py)
|
||||
- [判断信号是否连接](Demo/IsSignalConnected.py)
|
||||
- [调用虚拟键盘](Demo/CallVirtualKeyboard.py)
|
||||
|
||||
# QQ群
|
||||
|
||||
|
|
Loading…
Reference in a new issue