develia.org
»» i686 slackware tarballs..
»» software projects..
»» and much more..
 NAVIGATION 
 OPTIONS 

 INFO 
*** develia.org ***
by Giacomo Lozito
© 2004-2010

valid xhtml 1.0valid css!
powered by apachepowered by php
valid rss 2.0get firefox!

NO software patents in UE
 DOCUMENTS 
 emulatenumlock, NumLock key always on

I wrote this bash script, based on xmodmap, to make the numeric keypad behave as if NumLock was always turned on, ignoring its real state. In other words, by using this script, the numeric keypad will return numbers and dot key in any situation.
The script can be really useful to deal with some programs that seems to ignore NumLock state; in example, Unreal Tournament 2004 (™) and other SDL-based programs that do not read correctly keys pressed on the numeric keypad, behaving as if NumLock was always turned off. Emulatenumlock also allows to put things back to default state.
The script is written below and it is downloadable from this link, too.
By using xmodmap -pk it is possible to list keycodes and associated keysymnames, useful to eventually adjust the script for custom needs.

#!/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