mirror of
https://gitee.com/gfdgd-xi/deep-wine-runner
synced 2025-02-05 04:48:07 +08:00
快捷键编辑
This commit is contained in:
parent
c1d30e6e4d
commit
8c363d546a
Binary file not shown.
@ -15,12 +15,13 @@ keyChangeMap = [
|
|||||||
["enter", keyboard.Key.enter]
|
["enter", keyboard.Key.enter]
|
||||||
]
|
]
|
||||||
keyMap = []
|
keyMap = []
|
||||||
for i in os.listdir(f"{programPath}/key/list"):
|
for i in os.listdir(f"{programPath}/list"):
|
||||||
|
print(i)
|
||||||
try:
|
try:
|
||||||
file = open(f"{programPath}/key/list/{i}", "r")
|
file = open(f"{programPath}/list/{i}", "r")
|
||||||
keyMapTemp = json.loads(file.read())
|
keyMapTemp = json.loads(file.read())
|
||||||
except:
|
except:
|
||||||
print(f"{programPath}/key/list/{i} 读取失败!")
|
print(f"{programPath}/list/{i} 读取失败!")
|
||||||
continue
|
continue
|
||||||
for i in keyMapTemp:
|
for i in keyMapTemp:
|
||||||
keyMap.append(i)
|
keyMap.append(i)
|
||||||
@ -35,7 +36,7 @@ for i in range(len(keyMap)):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
print(keyList)
|
||||||
def on_press(key):
|
def on_press(key):
|
||||||
try:
|
try:
|
||||||
if key.char in keyList:
|
if key.char in keyList:
|
||||||
@ -48,7 +49,6 @@ def on_press(key):
|
|||||||
print(f'special key {key} pressed')
|
print(f'special key {key} pressed')
|
||||||
|
|
||||||
def on_release(key):
|
def on_release(key):
|
||||||
'松开按键时执行。'
|
|
||||||
print(f'{key} released')
|
print(f'{key} released')
|
||||||
try:
|
try:
|
||||||
del keyList[keyList.index(key.char)]
|
del keyList[keyList.index(key.char)]
|
||||||
@ -93,10 +93,8 @@ if os.path.exists("/tmp/deepin-wine-runner-keyboard-lock"):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
os.mknod("/tmp/deepin-wine-runner-keyboard-lock")
|
os.mknod("/tmp/deepin-wine-runner-keyboard-lock")
|
||||||
threading.Thread(target=Read).start()
|
threading.Thread(target=Read).start()
|
||||||
# Collect events until released
|
|
||||||
with keyboard.Listener(
|
with keyboard.Listener(
|
||||||
on_press=on_press,
|
on_press=on_press,
|
||||||
on_release=on_release) as listener:
|
on_release=on_release) as listener:
|
||||||
listener.join()
|
listener.join()
|
||||||
#listener.stop()
|
|
||||||
os.remove("/tmp/deepin-wine-runner-keyboard-lock")
|
os.remove("/tmp/deepin-wine-runner-keyboard-lock")
|
@ -1,12 +1,15 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
|
||||||
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string
|
||||||
sys.path.append(f"{programPath}/..")
|
sys.path.append(f"{programPath}/..")
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import dbus
|
import dbus
|
||||||
|
import json
|
||||||
import threading
|
import threading
|
||||||
|
import traceback
|
||||||
from UI.KeyAddKeyboardGui import *
|
from UI.KeyAddKeyboardGui import *
|
||||||
import PyQt5.QtWidgets as QtWidgets
|
import PyQt5.QtWidgets as QtWidgets
|
||||||
|
|
||||||
@ -19,6 +22,7 @@ class Check:
|
|||||||
try:
|
try:
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding").List()
|
bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding").List()
|
||||||
|
int("a")
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
print("无法检测到 Deepin/UOS 快捷键服务")
|
print("无法检测到 Deepin/UOS 快捷键服务")
|
||||||
@ -36,6 +40,9 @@ class Click:
|
|||||||
if ui.exeName.text() == "" or ui.localKey.text() == "" or ui.wineKey.text() == "":
|
if ui.exeName.text() == "" or ui.localKey.text() == "" or ui.wineKey.text() == "":
|
||||||
QtWidgets.QMessageBox.critical(window, "错误", "您的信息暂未填写完整")
|
QtWidgets.QMessageBox.critical(window, "错误", "您的信息暂未填写完整")
|
||||||
return
|
return
|
||||||
|
if ui.localKey.text()[0] == " " or ui.wineKey.text()[0] == " ":
|
||||||
|
QtWidgets.QMessageBox.critical(window, "错误", "映射快捷键的第一位不能为空格")
|
||||||
|
return
|
||||||
# Deepin/UOS 的情况
|
# Deepin/UOS 的情况
|
||||||
if Check.VersionCheck():
|
if Check.VersionCheck():
|
||||||
# 接入 dbus
|
# 接入 dbus
|
||||||
@ -51,6 +58,36 @@ class Click:
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||||
return
|
return
|
||||||
|
keyboardList = []
|
||||||
|
if os.path.exists(f"{programPath}/list/KeyList.json"):
|
||||||
|
try:
|
||||||
|
with open(f"{programPath}/list/KeyList.json") as file:
|
||||||
|
keyboardList = json.loads(file.read())
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||||
|
return
|
||||||
|
print(keyboardList)
|
||||||
|
addList = []
|
||||||
|
addList = keyListDebianMap[ui.wineKeyboardChoose.currentIndex()][:]
|
||||||
|
print(keyListDebianMap)
|
||||||
|
print(addList)
|
||||||
|
addList.append(ui.localKey.text()[0])
|
||||||
|
print(1, addList)
|
||||||
|
addList.append(f"'{programPath}/sendkeys.sh' {ui.wineKey.text()[0]} '{ui.exeName.text()}' {ui.wineKeyboardChoose.currentIndex()}")
|
||||||
|
print(2, addList)
|
||||||
|
print(addList)
|
||||||
|
try:
|
||||||
|
keyboardList[int(sys.argv[1])] = addList
|
||||||
|
except:
|
||||||
|
keyboardList.append(addList)
|
||||||
|
try:
|
||||||
|
with open(f"{programPath}/list/KeyList.json", "w") as file:
|
||||||
|
file.write(json.dumps(keyboardList))
|
||||||
|
QtWidgets.QMessageBox.information(window, "提示", "添加成功!")
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
QtWidgets.QMessageBox.critical(window, "错误", traceback.format_exc())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -58,13 +95,34 @@ if __name__ == "__main__":
|
|||||||
window = QtWidgets.QMainWindow()
|
window = QtWidgets.QMainWindow()
|
||||||
ui = Ui_MainWindow()
|
ui = Ui_MainWindow()
|
||||||
ui.setupUi(window)
|
ui.setupUi(window)
|
||||||
|
# 添加选项
|
||||||
|
ui.localKeyboardChoose.addItems(keyList)
|
||||||
|
ui.wineKeyboardChoose.addItems(keyList)
|
||||||
|
# 读取程序参数
|
||||||
|
try:
|
||||||
|
with open(f"{programPath}/list/KeyList.json") as file:
|
||||||
|
keyboardList = json.loads(file.read())
|
||||||
|
choice = keyboardList[int(sys.argv[1])]
|
||||||
|
ui.localKeyboardChoose.setCurrentIndex(keyListDebianMap.index(choice[:-2]))
|
||||||
|
ui.localKey.setText(choice[-2])
|
||||||
|
# 解析命令
|
||||||
|
command = choice[-1]
|
||||||
|
# 筛掉路径
|
||||||
|
command = command[command[1:].index("'") + 2:].strip()
|
||||||
|
# 筛出其中一个快捷键
|
||||||
|
ui.wineKey.setText(command[command.index(" ") - 1])
|
||||||
|
command = command[command.index(" ") + 2:]
|
||||||
|
# 读 exe
|
||||||
|
ui.exeName.setText(command[:command.index("'")])
|
||||||
|
command = command[command.index("'") + 1: ].strip()
|
||||||
|
# 读最后的快捷键
|
||||||
|
ui.wineKeyboardChoose.setCurrentIndex(int(command))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
# 连接槽
|
# 连接槽
|
||||||
ui.addButton.clicked.connect(Click.AddButton)
|
ui.addButton.clicked.connect(Click.AddButton)
|
||||||
ui.localKeyboardChoose.currentIndexChanged.connect(Click.LocalValueChange)
|
ui.localKeyboardChoose.currentIndexChanged.connect(Click.LocalValueChange)
|
||||||
ui.localKey.textChanged.connect(Click.LocalKeyChange)
|
ui.localKey.textChanged.connect(Click.LocalKeyChange)
|
||||||
window.show()
|
window.show()
|
||||||
# 添加选项
|
|
||||||
ui.localKeyboardChoose.addItems(keyList)
|
|
||||||
ui.wineKeyboardChoose.addItems(keyList)
|
|
||||||
#threading.Thread(target=Check.CheckThreading).start()
|
#threading.Thread(target=Check.CheckThreading).start()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
@ -1,3 +1 @@
|
|||||||
[
|
[["ctrl", "alt", "c", "'/home/gfdgd_xi/Desktop/deep-wine-runner/key/sendkeys.sh' b 'aa' 4"]]
|
||||||
["ctrl", "alt", "j", "'{programPath}/key/sendkeys.sh' a WeChat.exe 3"]
|
|
||||||
]
|
|
Loading…
x
Reference in New Issue
Block a user