Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Fluxbox handle capslock media keys

VLC lets you configure global hotkeys, so you can map your XF86AudioPrev and related keys. However, when my Capslock is on, my keyboard sends different keycodes. Here's my fix for that.

I wrote a shell script to handle the logic.

files/2024/listings/vlc-command (Source)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# Startdate: 2024-01-01-2 14:36
# Purpose: to be a hotkey target for when CapsLock is on but I still press "Play/Pause" media button on the keyboard.
# Usage:
#    In ~/.fluxbox/keys:
#    # For capslock, media previous, pause, skip
#    171 :Exec bin/vlc-command skip
#    172 :Exec bin/vlc-command play-pause
#    173 :Exec bin/vlc-command previous

case "${1}" in
   "play-pause")
      dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
      ;;
   "previous"|"back"|"left")
      dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
      ;;
   "next"|"skip"|"right")
      dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next
      ;;
esac

And then in my ~/.fluxbox/keys file I added these statements:

# For capslock, media previous, pause, skip
171 :Exec bin/vlc-command skip
172 :Exec bin/vlc-command play-pause
173 :Exec bin/vlc-command previous

I derived these of course with xev(1).

Errata

And the reason I sometimes end up with capslock on is I always use capslock to help wake on a monitor. I thought it was an XKCD comic that pointed out that Windows admins would use Ctrl+Alt+Delete to wake up a system, and that by default that reboots a Linux system, so when I have switched over to using all-Linux years ago, I use other methods (Capslock) to see if a system is awake/locked.

Comments