Difference between revisions of "Numlock State & Keyboard Mapping"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
(New page: __ _ -o)/ / (_)__ __ ____ __ Derek Winterstien /\\ /__/ / _ \/ // /\ \/ / r.o.a.c.h.@.r.o.b.o.t.z...c.o.m _\_v __/_/_//_/\_,_/ /_/\_\ C...)
(No difference)

Revision as of 19:30, 25 June 2007

__   _
  -o)/ /  (_)__  __ ____  __                   Derek Winterstien
  /\\ /__/ / _ \/ // /\ \/ /                   r.o.a.c.h.@.r.o.b.o.t.z...c.o.m
 _\_v __/_/_//_/\_,_/ /_/\_\

Creation Date: Fri Apr 23 13:08:17 CDT 2004                   current ver 0.20
------------------------------------------------------------------------------
NUMLOCK STATE & KEYBOARD MAPPING- numlock state control basic keyboard mapping
------------------------------------------------------------------------------

Introduction

Depending on how compiled, the Linux kernel tends to turn off the numlock key at boot. Even if configured to turn the numlock state on, the numlock state often goes off again when xwindows is started on most systems.


Numlock state for console

quick and easy numlock on at boot

To enable NumLock on by default, add these lines to

 /etc/rc.d/rc.sysinit
 for tty in /dev/tty[1-9]*; do
   setleds -D +num < $tty
 done

about setleds

Numlock state for xwindows

quick and easy numlock on for KDE

You can force the KDE Xwindows environment to turn on numlock by default. In fact, you have three options for "NumLock on KDE startup" which are: Turn on, Turn off, and Leave unchanged.

To locate and modify the numlock options for KDE do the following:

 Go to the start menu and select "Control Center".  Within the Control Center
 Index locate the "Peripherals" tree and expand it, then select "Keyboard".

numlock on for GNOME

It is not as simple to enable default numlock state on with GNOME. Apparently, there is a problem in GNOME with the keyboard options that causes a loss of keyboard functionality when numlock is enabled at startup. It only happens to some people, however, the GNOME developers decided not to include the option to enable numlock on startup.

You can enable it by Modifying the appropriate X startup script and adding the following line:

 setleds +num &> /dev/null

This should work without regards to your Windows Manager with the exception of those like KDE which will override the numlock state.

If you boot to runlevel 3 then you can add "setleds +num &> /dev/null" to the end of .bashrc file. Otherwise, you will get an error message every time you start a terminal. Also, the "setleds +num" doesn't work from a virtual console from within xwindows.

using setnumlock for GNOME

Easier yet is to acquire the program "setnumlock" and use it to set the numlock state to on at GNOME start. You need to acquire "setnumlock.tar.gz" which should be on this server's FTP site. Download the file and follow these steps. Also, make sure you have gcc installed, otherwise you will have to attempt to locate an already compiled binary.

 cd (change directory) to num-on (or wherever you downloaded the file)
 gzip -d setnumlock.tar.gz 
 tar xvf setnumlock.tar
 cd setnumlock
 type "make"
 then type "make install"

Make install has now created /usr/bin/setnumlock

  Open the start menu and goto "Preferences", then "More Preferences", 
  and "Session".  Click the Start Up Programs tab.  Click the Add button.   
  Browse to /usr/bin/setnumlock and add it then click "OK".

alternative method using keyboard mapping

Some Linux users will tell you that it is not always the best idea to have numlock enabled by default. Some programs are reported to behave strangely when numlock is on. It is said that it is because X treats NumLock as a modifier (like Shift, Ctrl etc.).

This alternative method is offered which will give you numlock like functionality from the number keypad without enabling numlock.

You can build a keymapping by adding keycode commands in your ~/.Xmodmap file. Use the following example by adding the lines below to .Xmodmap

 keycode 0x5A = 0
 keycode 0x57 = 1
 keycode 0x58 = 2
 keycode 0x59 = 3
 keycode 0x53 = 4
 keycode 0x54 = 5
 keycode 0x55 = 6
 keycode 0x4F = 7
 keycode 0x50 = 8
 keycode 0x51 = 9
 keycode 0x5B = period
 keycode 0x6C = Return
 keycode 0x56 = plus
 keycode 0x52 = minus
 keycode 0x3F = asterisk
 keycode 0x70 = slash
 keycode 0x4D = 

Now type the following command at console:

 xmodmap ~/.Xmodmap

simple c program to activate numlock key

This simple C program will activate the numlock state at the start of your Xwindows graphical environment.

Using the Vi editor, create a file called numlock.c and include the following lines of code:

 //numlock.c
 #include
 #include

 int main(void) {
         Display* disp = XOpenDisplay( NULL );
         if( disp == NULL )
                 return 1;
         XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock), True, CurrentTime );
         XTestFakeKeyEvent( disp, XKeysymToKeycode( disp, XK_Num_Lock), False, CurrentTime );
         XCloseDisplay( disp );
         return 0;  

}

Using the gcc compiler, execute the following command:

   gcc -I/usr/X11R6/include -L/usr/X11R6/lib -o setnumlock Numlock.c -lX11 -lXtst

This command will compile the above program and include files of the X libraries(package xdevel, series x). You will find a program called setnumlock in the current directory. You have to copy this file into the directory /usr/bin/local and make an entry in the file ~/.xinitrc.