[cumbria_lug] More on the numlock problem
Trevor Pearson
cumbria at mailman.lug.org.uk
Tue Jul 22 21:38:01 2003
Well,
I posted the 'console' script to turn numlock on on boot but the damn
thing only works if you're set to log in on a console i.e. text shell
prompt style,
Those that log in using X and go directly to GUI/wimp interface like KDE
or Gnome, well the little script just don't work.
SO
IF you're a mouse-pusher type then you need a different approach,
Here is the secret ....
Type in the following 'C' program using a graphical text editor like
'kate'
and save it in a file called 'numlock.c' then click on the 'terminal' or
'shell'
icon this will bring up a window (Still safely gui) but you need to type
the following line exactly into the window and press the 'Return' key.
Note it should be all one line and is case sensitive.
gcc -Wall -ansi -O2 -I/usr/X11R6/include -L/usr/X11R6/lib -o setnumlock
numlock.c -momit-leaf-frame-pointer -lX11 -lXtst
When this finishes and you see the prompt type ./setnumlock
and the numlock will turn on and off !
The 'Code' is :-
#include <X11/extensions/Xtest.h>
#include <X11/keysym.h>
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;
}
--
Trevor Pearson <trevor@haven.demon.co.uk>
http://www.haven.demon.co.uk
http://bigtrev.port5.com