全部博文(930)
分类: LINUX
2008-11-11 16:30:29
// xnumlock.c使用下面命令编译:
// set numlock on by xunet 2007.4.4
#i nclude#i nclude
int get_numlock_state(Display* disp)
{
int i;
int numlock_mask = 0;
Window dummy1, dummy2;
int dummy3, dummy4, dummy5, dummy6;
unsigned int mask;
XModifierKeymap* map = XGetModifierMapping( disp );
KeyCode numlock_keycode = XKeysymToKeycode( disp, XK_Num_Lock );
if( numlock_keycode == NoSymbol )
return0;
for( i = 0; i < 8; ++i ) {
if( map->modifiermap[map->max_keypermod * i ] == numlock_keycode)
numlock_mask = 1 < }
XQueryPointer( disp,DefaultRootWindow( disp ), &dummy1,&dummy2,
&dummy3, &dummy4, &dummy5, &dummy6,&mask );
XFreeModifiermap( map );
return mask & numlock_mask;
}
int main(int argc, char* argv[]){
Display* disp = XOpenDisplay(NULL);
if (disp == NULL) return1;
if(get_numlock_state(disp)) return0; //already on
//set numlock on
XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), True,
CurrentTime);
XTestFakeKeyEvent(disp, XKeysymToKeycode(disp, XK_Num_Lock), False,
CurrentTime);
XCloseDisplay(disp);
return0;
}