0

I want to map the action ctrl+shift+tab + scroll to volume up/down. How can I achieve this?

I know that ctrl + scroll maps to zoom in/out by default. Surely, there must be a way to create such a custom shortcut no?

(I am running kde plasma 5.14.5)

1

As far as my reseach went, I wasn't able to find any elegant solution to the problem. I hacked a very crude python script that does the job poorly... I'm sorry.

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()

The problem with this is that you need to press ctrl + shift + scoll up/down and then RE-PRESS shift to toggle the action again. I mean it's annyong. Also this does not block the scroll, so you might want to scroll on a neutral place (like a sidebar).

This uses pynput but I hope that won't be a problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.