The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 1,678     Votes:  8 
Tags: sound   keyboard   capslock  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

URL: https://askubuntu.com/q/1047224
Title: Can I remap the Caps Lock key to play audio?
ID: /2018/06/16/Can-I-remap-the-Caps-Lock-key-to-play-audio_
Created: June 16, 2018    Edited:  June 12, 2020
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


In Ubuntu 16.04 after spending hours googling & fiddling with dconf-editor and xbindkeys I found an extremely easy solution:


If you need Gnome XF86AudioPlay support you need xdotool (not needed for VLC as OP stipulates):

sudo apt install xdotool

Now here’s the tricky part. Every time you press the Caps LocK key to toggle the music between Play and Pause, capital letters also toggle off and on.

Use this method to turn off Caps Lock toggling while still keeping key active:

setxkbmap -option caps:none

Music players that adhere to Gnome

Then in Ubuntu 16.04 go into Settings » Keyboard » Shortcuts » Custom Shortcuts:

audio pause-play shortcut.png

After adding the new option the assigned shortcut key will read Disabled. Click on Disabled and when prompted for key to assign press the Caps LocK key.


Music players like VLC

Follow the steps for Gnome in the previous section but for the command use this instead:

qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

VLC won’t recognize media keys: How to make the keyboard media keys to work with VLC globally?y even when built into the keyboard. Therefor the custom keyboard shortcut to XF86AudioPlay is useless with xdotool.


Setting custom keyboard shortcuts from command line

This Q&A discusses how to set custom keyboard shortcuts from the command line: How to set custom keyboard shortcuts from terminal?


Deactivating caps lock permanently

Next step is to make this setxkbmap -option caps:none persistent across reboots. Googling results in this answer by Terdon: Save setxkbdmap settings:

An easy way would be to add the command to your $HOME/.profile file (you can create it if it doesn’t exist):

setxkbmap -option caps:none

That should make it run every time you log in.

Note that you should use $HOME/.profile rather than $HOME/.bash_profile, $HOME/.bashrc or some other similar file. This is because this setting should be read by your login manager.

⇧ How to make calendar points to Sunday as first day of the week in Ubuntu 18.04 Ubuntu 18.04 LTS hangs up every time with AMD GPU  ⇩