Unix Technical Forum

NumLock on at login!?

This is a discussion on NumLock on at login!? within the Sun Solaris Hardware forums, part of the Solaris Operating System category; --> Hey, is there a way to activate NumLock automatically when I login at the console (or in general)? uname ...


Go Back   Unix Technical Forum > Unix Operating Systems > Solaris Operating System > Sun Solaris Hardware

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 12:28 PM
Peter
 
Posts: n/a
Default NumLock on at login!?

Hey,

is there a way to activate NumLock automatically when I login at the
console (or in general)?

uname -a yields " SunOS host 5.8 Generic_108528-21 sun4u sparc
SUNW,Ultra-5_10 ".

I would appreciate helpful hints, especially when they are not too cryptic
;-) since I'm a novice.

Thanks,

Peter

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-16-2008, 12:28 PM
Greg Sellers
 
Posts: n/a
Default Re: NumLock on at login!?


You mean so you don't have to "push" the NumLock key when you login,
like when you power on your peecee, right?

Nope, there is no way to do this. It drives me nuts, I bug my buddy
at Sun about it all the time too. Best idea we came up with was to
wait after logging out for the login screen to appear and then push
the NumLock before you leave for the day, then it is already set for
the next day...just have to remember to do it.

-Greg


Peter wrote:
>
> Hey,
>
> is there a way to activate NumLock automatically when I login at the
> console (or in general)?
>
> uname -a yields " SunOS host 5.8 Generic_108528-21 sun4u sparc
> SUNW,Ultra-5_10 ".
>
> I would appreciate helpful hints, especially when they are not too cryptic
> ;-) since I'm a novice.
>
> Thanks,
>
> Peter

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 12:31 PM
Richard L. Hamilton
 
Posts: n/a
Default Re: NumLock on at login!?

In article <Pine.SOL.4.58.0311121719520.15199@ataman.cfa.harv ard.edu>,
Peter <per@web.de> writes:
> Hey,
>
> is there a way to activate NumLock automatically when I login at the
> console (or in general)?
>
> uname -a yields " SunOS host 5.8 Generic_108528-21 sun4u sparc
> SUNW,Ultra-5_10 ".
>
> I would appreciate helpful hints, especially when they are not too cryptic
> ;-) since I'm a novice.
>


I found a program meant for Linux to do this. Unfortunately, it compiles,
but doesn't seem to have any effect.

http://sdb.suse.de/sdb/en/html/cg_x11numlock.html

It uses the XTEST extension to generate a press and release of numlock.

However, that got me to thinking: the lock keys on Sun keyboards don't
physically lock, that's handled in software. So I commented out the
second call to XTestFakeKeyEvent (the one that generates the release),
and it worked!

Unfortunately, it doesn't turn on the numlock light. But someone could
fix that if they wanted to; setting the lights is easy enough. However,
there's probably no portable way to do it, since XGetKeyboardControl(3)
says "No standard interpretation of LEDs is defined.", i.e. which LED
is the NumLock LED varies across different implementations of the X server.

One could maybe come up with a proper way of doing it all by enabling and
using the X keyboard extension, but to my mind, that's not quite ready for
prime time yet (still too many quirks), although it's getting better.

--
mailto:rlhamil@smart.net http://www.smart.net/~rlhamil
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 12:31 PM
Richard L. Hamilton
 
Posts: n/a
Default Re: NumLock on at login!?

In article <vro8r7a402kg7e@corp.supernews.com>,
Richard.L.Hamilton@mindwarp.smart.net (Richard L. Hamilton) writes:
> In article <Pine.SOL.4.58.0311121719520.15199@ataman.cfa.harv ard.edu>,
> Peter <per@web.de> writes:
>> Hey,
>>
>> is there a way to activate NumLock automatically when I login at the
>> console (or in general)?
>>
>> uname -a yields " SunOS host 5.8 Generic_108528-21 sun4u sparc
>> SUNW,Ultra-5_10 ".
>>
>> I would appreciate helpful hints, especially when they are not too cryptic
>> ;-) since I'm a novice.
>>

>
> I found a program meant for Linux to do this. Unfortunately, it compiles,
> but doesn't seem to have any effect.
>
> http://sdb.suse.de/sdb/en/html/cg_x11numlock.html
>
> It uses the XTEST extension to generate a press and release of numlock.
>
> However, that got me to thinking: the lock keys on Sun keyboards don't
> physically lock, that's handled in software. So I commented out the
> second call to XTestFakeKeyEvent (the one that generates the release),
> and it worked!
>
> Unfortunately, it doesn't turn on the numlock light. But someone could
> fix that if they wanted to; setting the lights is easy enough. However,
> there's probably no portable way to do it, since XGetKeyboardControl(3)
> says "No standard interpretation of LEDs is defined.", i.e. which LED
> is the NumLock LED varies across different implementations of the X server.
>
> One could maybe come up with a proper way of doing it all by enabling and
> using the X keyboard extension, but to my mind, that's not quite ready for
> prime time yet (still too many quirks), although it's getting better.


I modified the original considerably, and now it should try to do it
the original way, and if that doesn't work, try to do it without the
release. That works for me on Solaris; it should also work on Linux,
but I don't have anything to test it on.

I also added some code that on Solaris only will turn on the NumLock LED.
It uses a hard-coded table of server vendor string vs LED number; that
could be extended to handle other servers, or other tricks could be added.

It's probably neither clean nor robust in the face of all possible
failures, but it seems to work fine.

Code follows. Remember to link with -lX11 -lXtst (and precede on older
Solaris with -L/usr/openwin/lib -R/usr/openwin/lib).


/* numlock.c */
/*
* heavily modified version of something seen at
* http://sdb.suse.de/sdb/en/html/cg_x11numlock.html
*
* rlhamil@mindwarp.smart.net
*/

#include <X11/extensions/XTest.h>
#include <X11/keysym.h>
#include <stdlib.h>
#include <string.h>

#define PRESS 1
#define RELEASE 2
#define BOTH (PRESS|RELEASE)

void
fake_key_events(Display *disp, int key, int which)
{
if (which&PRESS)
XTestFakeKeyEvent(disp,key,True,CurrentTime);
if (which&RELEASE)
XTestFakeKeyEvent(disp,key,False,CurrentTime);
}

void
numlock_on(Display *disp)
{
static KeyCode numlock=0;
static unsigned int numlockmask=0;
static struct {
char *name;
int lednum;
} vendor2NumLockLED[] = {
{ "Sun Microsystems, Inc.", 1},
{ "The XFree86 Project, Inc", 0}, /* none did it on laptop I tried */
{ NULL, 0 }
};
Window rr, cr;
int rxr, ryr, wxr, wyr, led=0, l;
unsigned int before, after;
char *p;

if (numlock == 0) {
XModifierKeymap *mk;
int m, k;

numlock=XKeysymToKeycode(disp,XK_Num_Lock);
mk=XGetModifierMapping(disp);
for (m=0;m<8;m++) {
for (k=0;k < mk->max_keypermod; k++) {
if (mk->modifiermap[m*mk->max_keypermod+k]==numlock) {
numlockmask=(1<<m);
break;
}
}
}
XFreeModifiermap(mk);
if (numlockmask==0) {
/* num lock key not assigned to any modifier */
XCloseDisplay(disp);
exit(2);
}
}

XQueryPointer(disp, DefaultRootWindow(disp),&rr,&cr,&rxr,&ryr,&wxr,&wy r,
&before);
before &= numlockmask;

fake_key_events(disp, numlock, BOTH); /* try like the original version */

XQueryPointer(disp, DefaultRootWindow(disp),&rr,&cr,&rxr,&ryr,&wxr,&wy r,
&after);
after &= numlockmask;

if (before==after) /* i.e. if that didn't work */
fake_key_events(disp, numlock, PRESS); /* try just the press */

/* now take a shot at guessing the right LED for NumLock based on the
server's vendor string using the hardcoded table previously declared */
p=ServerVendor(disp);

for (l=0;vendor2NumLockLED[l].name!=NULL;l++)
if (!strcmp(p,vendor2NumLockLED[l].name) &&
vendor2NumLockLED[l].lednum) {
led=vendor2NumLockLED[l].lednum;
break;
}

if (led) {
XKeyboardControl values;
values.led=led;
values.led_mode=LedModeOn;
XChangeKeyboardControl(disp,KBLed|KBLedMode,&value s);
}
}

int
main(int argc, char **argv)
{
Display *disp = XOpenDisplay(NULL);
if (disp == NULL)
return 1;

numlock_on(disp);

XCloseDisplay(disp);

return 0;
}



--
mailto:rlhamil@smart.net http://www.smart.net/~rlhamil
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 12:31 PM
Alan Coopersmith
 
Posts: n/a
Default Re: NumLock on at login!?

Richard.L.Hamilton@mindwarp.smart.net (Richard L. Hamilton) writes in comp.sys.sun.hardware:
|Unfortunately, it doesn't turn on the numlock light. But someone could
|fix that if they wanted to; setting the lights is easy enough. However,
|there's probably no portable way to do it, since XGetKeyboardControl(3)
|says "No standard interpretation of LEDs is defined.", i.e. which LED
|is the NumLock LED varies across different implementations of the X server.

For XFree86, using XKB should get you the LED mappings. For Xsun when
XKB is not enabled (the default on current releases), there is a way to
find out - _SUN_LED_MAP. I don't think it's really documented (it's
mentioned without details in the keytables in /usr/openwin/etc/keytables
), but there is some sample code out there using it:
http://www.mit.edu/afs/sipb/project/.../olwm/client.c

You would look for which one has the value XK_Num_Lock. On my system,
xprop -root shows:
_SUN_LED_MAP(INTEGER) = 4, 65407, 65312, 65300, 65509, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

/usr/include/X11/keysymdef.h says:
#define XK_Num_Lock 0xFF7F

which translates to 65407 decimal, or LED #1. (Of course grepping
through the keytables, it looks like 1 is the only value we ever use, so
hardcoding it works just as well.)

--
__________________________________________________ ______________________
Alan Coopersmith alanc@alum.calberkeley.org
http://www.CSUA.Berkeley.EDU/~alanc/ aka: Alan.Coopersmith@Sun.COM
Working for, but definitely not speaking for, Sun Microsystems, Inc.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:16 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com