deep-wine-runner/helper/tools/add_hotkeys
2024-01-29 14:02:28 +08:00

60 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# vim: set ts=4 sw=4 fileencoding=utf-8:
# Luomio <nohappiness@gmail.com>
# Filename: dde-first-run.py
# Create Date: 27-03, 13
from os import path, rename, remove
import locale
import subprocess
import os
import shutil
import json
import math
import dbus
_action = "/opt/deepinwine/tools/sendkeys.sh"
def system_screenshot_isA():
bus = dbus.SessionBus()
keybinding = bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding")
keybinding_iface = dbus.Interface(keybinding, dbus_interface='com.deepin.daemon.Keybinding')
obj = json.loads(keybinding_iface.List())
for i in range(len(obj)):
if obj[i]['Id'] == "screenshot":
if '<Control><Alt>A' in obj[i]['Accels']:
return True
return False
def add_qq_shortcut(_name, _key, _short_cut):
if path.exists(_action):
bus = dbus.SessionBus()
keybinding = bus.get_object("com.deepin.daemon.Keybinding", "/com/deepin/daemon/Keybinding")
keybinding_iface = dbus.Interface(keybinding, dbus_interface='com.deepin.daemon.Keybinding')
obj = json.loads(keybinding_iface.List())
for i in range(len(obj)):
if obj[i]['Name'] == _name:
keybinding_iface.Delete(obj[i]['Id'], obj[i]['Type'])
_, ok = keybinding_iface.Add(_name, _action+_key, _short_cut)
if ok == False:
return False
if __name__ == "__main__":
import sys
_action = os.path.realpath(os.path.dirname(sys.argv[0]))
_action = os.path.join(_action, "sendkeys.sh")
if len(sys.argv) < 4:
add_qq_shortcut(u"提取QQ消息", " z", "<Control><Alt>Z")
if system_screenshot_isA():
add_qq_shortcut(u"QQ截图", " a", "<Control><Alt>S")
else:
add_qq_shortcut(u"QQ截图", " a", "<Control><Alt>A")
sys.exit(0)
add_qq_shortcut(str(sys.argv[1]), sys.argv[2], sys.argv[3])