How do I programmatically toggle Mouse Keys

Using Mate on Ubuntu 20.04

From Control Center->Keyboard Preferences->Mouse Keys, it is a simple matter to turn keypad
control of the mouse pointer on and off.

I would like to programmatically toggle this service.

Research via google suggests using gsettings but that method is perhaps deprecated.
From Ubuntu – Turn Mousekeys on/off from keyboard – iTecTec the example
code does not work. I read from other discussions that shift+numlock should effect a toggle,
but that does not work on my setup either. I would note also that Mouse Keys works with both
Numlock on and off.

Advice on how to proceed would be greatly appreciated.
Thanks

1 Like

The problem with the guide that you linked is that it was written for Ubuntu with the GNOME desktop environment. (OK. maybe by then it was Unity. But in terms of configurability under the hood, Unity was effectively a wrapper around GNOME.) MATE uses a different configuration "key" to store the Mouse Keys setting; you just need to use the right key.

Short answer: This command turns Mouse Keys on:

gsettings set org.mate.accessibility-keyboard mousekeys-enable true

This command turns Mouse Keys off:

gsettings set org.mate.accessibility-keyboard mousekeys-enable false

And this script toggles the state of Mouse Keys:

#!/bin/bash

MOUSE_KEYS_ON=$(gsettings get org.mate.accessibility-keyboard mousekeys-enable)

if [ "$MOUSE_KEYS_ON" = false ]; then
    gsettings set org.mate.accessibility-keyboard mousekeys-enable true
elif [ "$MOUSE_KEYS_ON" = true ]; then
    gsettings set org.mate.accessibility-keyboard mousekeys-enable false
else
    echo 'Something is wrong!  We could not figure out what state Mouse Keys is in --'
    echo 'whether it is on or off, that is.  Are you using the MATE desktop?'
    exit 1
fi

exit 0

Thank you for the solution gordon. I figured it would be something like that and I had been
perusing dconf-editor to try to find the setting and extrapolate from there.
Good job.
cheers
P.S. don't find where to mark as solved.

1 Like

I think I figured out how to mark this topic as solved. So thanks again to Gordon. Also, I Read The Friendly Manual on gsettings. From that I derived the following invocation:

gsettings list-recursively > gsettings.txt
and
vim gsettings.txt
So now I have a searchable pseudo-database

1 Like