moses-palmer / pynput

Sends virtual input commands

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pynput not detecting media keys on kde plasma wayland

walksanatora opened this issue · comments

Description
A clear and concise description of what the bug is.
all keyboard and numpad keys (excluding the media keys) are being detected but not the play/pause, stop, or skip foward/back buttons

Platform and pynput version
Your operating system and version, and the version of pynput.
Linux archiev3 6.6.6-arch1-1 #1 SMP PREEMPT_DYNAMIC Mon, 11 Dec 2023 11:48:23 +0000 x86_64 GNU/Linux
pynput 1.7.6
I should also specify I am on wayland desktop

To Reproduce

def on_press(key):
    if str(key) == 'Key.media_next':
        print("media next")
    elif str(key) == 'Key.media_play_pause':
        print("media play/pause")
    elif str(key) == '<269025045>':
        print("media stop")
    elif str(key) == 'Key.media_previous':
        print("media previous")
    else: 
        print("unknown key:", str(key))
        pass

listener_thread = Listener(on_press=on_press, on_release=None)
listener_thread.start()

while true:
    pass

press mmedia keys and none appear

Hello,

I have had a similar issue in KDE plasma wayland.

My function keys f13-f18 (haven't tested further yet) do not work.

I think this is because "under the hood," pynput does not have bindings for wayland but only for xorg.

Here is what my code looks like, btw. Nice to see that somebody else has found another way to work around this issue:

#!/usr/bin/python3

# toggles LEDs based on the button pressed

import sys
import sal_kblib as sal
import json
from pynput import keyboard
from threading import Event

def on_press(key):
    print(key)
    if key == keyboard.KeyCode(269025153):
        sal.toggle_led(interface, 0)
    if key == keyboard.KeyCode(269025093):
        sal.toggle_led(interface, 1)
    if key == keyboard.KeyCode(269025094):
        sal.toggle_led(interface, 2)
    if key == keyboard.KeyCode(269025095):
        sal.toggle_led(interface, 3)
    if key == keyboard.KeyCode(269025096):
        sal.toggle_led(interface, 4)
    if key == keyboard.KeyCode(269025097):
        sal.toggle_led(interface, 5)


if __name__ == '__main__':
    evnt = Event()
    interface = sal.get_hid_interface();

    listener = keyboard.Listener(on_press = on_press)
    listener.start()

    while True:
        # essentially does nothing but reset the watchdog
        sal.toggle_led(interface, 0xff)
        evnt.wait(1);