forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CallVirtualKeyboard.py
68 lines (59 loc) · 2.4 KB
/
CallVirtualKeyboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2019年5月22日
@author: Irony
@site: https://pyqt.site , https://github.com/PyQt5
@email: [email protected]
@file: Demo.CallVirtualKeyboard
@description: 调用系统虚拟键盘
"""
import glob
try:
from PyQt5.QtCore import QProcess, QSysInfo
from PyQt5.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton
except ImportError:
from PySide2.QtCore import QProcess, QSysInfo
from PySide2.QtWidgets import QApplication, QWidget, QTextEdit, QVBoxLayout, QPushButton
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
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())