From dbb152d9ebbe569fecca8ef9be3259bfeb29a9f0 Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Fri, 7 Oct 2022 21:27:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0=E6=8C=89?= =?UTF-8?q?=E9=94=AE=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KeyList.json | 3 ++ deepin-wine-packager.py | 2 +- key-get.py | 83 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 KeyList.json create mode 100644 key-get.py diff --git a/KeyList.json b/KeyList.json new file mode 100644 index 0000000..0d3f271 --- /dev/null +++ b/KeyList.json @@ -0,0 +1,3 @@ +[ + ["ctrl", "alt", "j", "ls"] +] \ No newline at end of file diff --git a/deepin-wine-packager.py b/deepin-wine-packager.py index 809beb8..b49f1ce 100755 --- a/deepin-wine-packager.py +++ b/deepin-wine-packager.py @@ -942,7 +942,7 @@ Description: {e3_text.text()} ################ if not self.build: self.label.emit("正在构建 deb 包……") - self.run_command("dpkg -b {} {}".format(debPackagePath, e12_text.text())) + self.run_command("bash -c 'dpkg -b {} {}'".format(debPackagePath, e12_text.text())) ################ # 完成构建 ################ diff --git a/key-get.py b/key-get.py new file mode 100644 index 0000000..f2f956f --- /dev/null +++ b/key-get.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python3 +import os +import sys +import time +import json +import threading +import traceback +import pynput.keyboard as keyboard +keyList = [] +'''keyMap = [ + [keyboard.Key.ctrl, keyboard.Key.alt, "j", "ls"] +]''' +keyChangeMap = [ + ["ctrl", keyboard.Key.ctrl], + ["alt", keyboard.Key.alt], + ["esc", keyboard.Key.esc], + ["enter", keyboard.Key.enter], +] +programPath = os.path.split(os.path.realpath(__file__))[0] # 返回 string +file = open(f"{programPath}/KeyList.json", "r") +keyMap = json.loads(file.read()) +for i in range(len(keyMap)): + for k in range(len(keyMap[i])): + for j in keyChangeMap: + if keyMap[i][k] == j[0]: + keyMap[i][k] = j[1] + +def on_press(key): + try: + if key.char in keyList: + # 重复的值就不认了,摊牌了 + return + keyList.append(key.char) + print(f'alphanumeric key {key.char} pressed') + except AttributeError: + keyList.append(key) + print(f'special key {key} pressed') + +def on_release(key): + '松开按键时执行。' + print(f'{key} released') + try: + del keyList[keyList.index(key.char)] + except AttributeError: + del keyList[keyList.index(key)] + except: + traceback.print_exc() + +def ReadKey(): + next = False + command = "" + for i in keyMap: + for k in range(0, len(i) - 1): + k = i[k] + if not k in keyList: + next = True + break + if not next: + # 执行命令 + os.system(i[-1]) + # 必须等待按键全部松开才行 + while len(keyList) != 0: + time.sleep(0.01) + + +def Read(): + while True: + ReadKey() + time.sleep(0.01) + +# Lock 锁防止多次调用 +if os.path.exists("/tmp/deepin-wine-runner-keyboard-lock"): + print("不可多次调用") + print("锁 /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() +os.remove("/tmp/deepin-wine-runner-keyboard-lock") \ No newline at end of file