Turn Mousekeys on/off from keyboard

I had the same problem. I'm also (still) on Ubuntu 11.10.

In my everyday work I use mousekeys primarily because I like using the num-5 key for mouse key presses.

Then I discovered that in Unity you can do very nice window tiling (ctrl-alt-num4 sends a window to the left of the screen, ctrl-alt-num6 to the right, ctrl-alt-9 top-right, etc).

So to do my window tiling I want to momentarily disable mousekeys.

I found the answer here: http://ubuntuforums.org/showpost.php?p=11776864&postcount=4

I saved the script as ubuntu-toggle-mousekeys and when I need to I type:

bash ubuntu-toggle-mousekeys

... in my terminal.

Here's my very slightly amended script - I just added some comments really:

#!/bin/bash

# http://ubuntuforums.org/showthread.php?t=1942984

# I needed this when I connected a big monitor to my ubuntu laptop.
# Unity has nice window tiling shortcuts that need the number keypad to work.
# ctrl-alt-num4 sends a window left, ctrl-alt-num6 sends a window right, etc.

STATUS=$(gsettings get org.gnome.desktop.a11y.keyboard mousekeys-enable) #Are mousekeys on (true or false)

if [ "$STATUS" == "true" ]
then
  gsettings set org.gnome.desktop.a11y.keyboard mousekeys-enable false 

  notify-send -i  "/usr/share/icons/gnome/48x48/devices/keyboard.png" "                    Mousekeys OFF"
  echo "Mousekeys are OFF - use ctrl-alt-num4 to send window left, ctrl-alt-num6 to send window right"

else
  gsettings set org.gnome.desktop.a11y.keyboard mousekeys-enable true

  notify-send -i  "/usr/share/icons/gnome/48x48/devices/keyboard.png" "                    Mousekeys ON"
  echo "Mousekeys are ON"
fi

bash code didn't work , try this :

#!/usr/bin/env ruby

# http://ubuntuforums.org/showthread.php?t=1942984

# I needed this when I connected a big monitor to my ubuntu laptop.
# Unity has nice window tiling shortcuts that need the number keypad to work.
# ctrl-alt-num4 sends a window left, ctrl-alt-num6 sends a window right, etc.

#Are mousekeys on (true or false)
r = `gsettings get org.gnome.desktop.a11y.keyboard mousekeys-enable`

p r

if r =~ /true/i
  `gsettings set org.gnome.desktop.a11y.keyboard mousekeys-enable false `
  `notify-send -i  "/usr/share/icons/gnome/48x48/devices/keyboard.png" "Mousekeys OFF" `
  puts "Mousekeys are OFF - use ctrl-alt-num4 to send window left, ctrl-alt-num6 to send window right"

else
  `gsettings set org.gnome.desktop.a11y.keyboard mousekeys-enable true `

  `notify-send -i  "/usr/share/icons/gnome/48x48/devices/keyboard.png" "Mousekeys ON" `
  p "Mousekeys are ON"
end