#!/bin/bash
#
# "NumLock always on" script
# Version 0.1 by Giacomo Lozito
# Last edited on 23/7/2004
# License: General Public License v2
#
# This script uses xmodmap to remap the keys on numeric keypad,
# so that they behave as if NumLock was always turned on.
# Things can be also reversed back to normal state as well.
#


function nlo_start() {
  xmodmap -quiet \
  -e "keysym KP_Delete = KP_Decimal" \
  -e "keysym KP_Insert = KP_0" \
  -e "keysym KP_End = KP_1" \
  -e "keysym KP_Down = KP_2" \
  -e "keysym KP_Next = KP_3" \
  -e "keysym KP_Left = KP_4" \
  -e "keysym KP_Begin = KP_5" \
  -e "keysym KP_Right = KP_6" \
  -e "keysym KP_Home = KP_7" \
  -e "keysym KP_Up = KP_8" \
  -e "keysym KP_Prior = KP_9"
}

function nlo_stop() {
  xmodmap -quiet \
  -e "keycode 91 = 0xff9f 0xffae" \
  -e "keycode 90 = 0xff9e 0xffb0" \
  -e "keycode 87 = 0xff9c 0xffb1" \
  -e "keycode 88 = 0xff99 0xffb2" \
  -e "keycode 89 = 0xff9b 0xffb3" \
  -e "keycode 83 = 0xff96 0xffb4" \
  -e "keycode 84 = 0xff9d 0xffb5" \
  -e "keycode 85 = 0xff98 0xffb6" \
  -e "keycode 79 = 0xff95 0xffb7" \
  -e "keycode 80 = 0xff97 0xffb8" \
  -e "keycode 81 = 0xff9a 0xffb9"
}

case "$1" in
  start)
    nlo_start
    ;;

  stop)
    nlo_stop
    ;;

  *)
    echo $"Usage: $0 {start|stop}"
    exit 1
esac
