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