创建键盘键 + 滚动的快捷方式

创建键盘键 + 滚动的快捷方式

我想将操作映射ctrl+shift+tab + scroll到音量增大/减小。我怎样才能实现这个目标?

我知道ctrl + scroll地图默认会放大/缩小。当然,一定有办法创建这样的自定义快捷方式不是吗?

(我正在运行 kde Plasma 5.14.5)

答案1

就我的研究而言,我无法找到解决该问题的任何优雅的解决方案。我破解了一个非常粗糙的 python 脚本,它的工作效果很差......我很抱歉。

from pynput import keyboard
from pynput import mouse
from pynput.keyboard import Controller
import subprocess
from subprocess import call

kbd = Controller()

COMBINATIONS = [{keyboard.Key.ctrl, keyboard.Key.shift}]

current = set()

def execute():
    with mouse.Listener(on_scroll=on_mscroll) as listener:
        listener.join()

def on_press(key):
    if any([key in COMBO for COMBO in COMBINATIONS]):
        current.add(key)
        if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
            # this executes only once and then it looses the keycombination
            execute()

def on_release(key):
    if any([key in COMBO for COMBO in COMBINATIONS]):
        try:
            current.remove(key)
        except KeyError:
            pass

def on_mscroll(x, y, dx, dy):
    if dy < 0:
        # this can be changed to the appropriate command to change the volume
        # like pactl
        call(["amixer", "-D", "pulse", "sset", "Master", "5%-"],stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    else:
        call(["amixer", "-D", "pulse", "sset", "Master", "5%+"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
    return False

with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
    listener.join()

这样做的问题是,您需要按ctrl+ shift+ 向上/向下滚动,然后重新shift按以再次切换操作。我的意思是这是安永。此外,这不会阻止滚动,因此您可能希望在中立位置(例如侧边栏)上滚动。

这个有用pynput,但我希望这不会成为问题

相关内容