Open rtaibah opened 5 years ago
Never encountered that one before 😬. Please run the code snippet below to help me figure out what's happening:
from AppKit import NSApplication, NSApplicationActivationPolicyProhibited
from AppKit import NSSystemDefined
from AppKit import NSKeyUp
from PyObjCTools import AppHelper
class KeySocketApp(NSApplication):
def sendEvent_(self, event):
if event.type() is NSSystemDefined and event.subtype() == 8:
data = event.data1()
key_code = (data & 0xFFFF0000) >> 16
key_flags = (data & 0x0000FFFF)
key_state = (key_flags & 0xFF00) >> 8
if key_state is NSKeyUp:
print("Key up detected.")
elif key_code == 20 or key_code == 18:
print("Previous key detected")
elif key_code == 16:
print("Play/pause key detected")
elif key_code == 19 or key_code == 17:
print("Next key detected.")
else:
print(f"Unknown key code: {key_code}")
app = KeySocketApp.sharedApplication()
app.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
AppHelper.runEventLoop()
Here is the output. Not very helpful, so I made a video too.
rami@MacBook-Pro-4 ~/Music #python3 debug.py
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
I introduced a config variable named THROTTLE_INTERVAL
to resolve this issue. It controls for how long key presses are ignored after the last key-press. Setting it to ~ 2.0
should hopefully fix the problem 🙂
Please upgrade to the most recent version (v3.0.4 at the time of writing), delete your config file and set an appropriate interval.
rm $(EDITOR=echo cmus-osx config)
cmus-osx config
This partially fixed the issue. Pressing play plays the music, however pausing pauses for a few seconds and plays again.
Things I done/things I noticed:
1- I changed a bit in the THROTTLE_INTERVAL
variable, all the way up to 20.0.
2- The play icon on my Mac's touchbar doesn't change to pause or vice versa
3- I am not playing anything from my local system, but streaming a .pls file.
4- Doing your suggestion made the buttons unresponsive. Only after restarting I got the behaviour I describe here.
When using the media keys both on the my Mac and an external keyboard, they register but the action is immediately reversed. So if I press play I hear the music playing for a fraction of a second then stops. And if I press pause the music stops for a fraction of a second and plays again.
In both cases notifications are triggered.