lockkeys编译方法:cc -o lockkeys lockkeys.c
实现步骤:
1、将lockkeys执行程序拷贝到/etc目录下,并赋予执行权限;
2、把numlock.init.string中的代码加入到/etc/inittab文件中指令行的第一行。
numlock.init.string代码内容:
snum::sysinit:/etc/lockkeys numlock on < /dev/console >/dev/console 2>&1
lockkeys源代码:
/*
* Program to control the console lock keys states
*
* Build with "cc -o lockkeys lockkeys.c"
*/
#include
#include
#include
#include
#define RDFD 0
#define CAPSLOCK 0x01
#define NUMLOCK 0x02
#define SCROLLLOCK 0x04
void main( argc, argv )
int argc;
char *argv[];
{
char c;
int function, key;
if ( argc != 3 ) {
fprintf( stderr, "Usage: lockkeys key on | off | toggle
" );
exit( 1 );
}
if ( !strcmp( argv[2], "off" ))
function=0;
else if ( !strcmp( argv[2], "on" ))
function=1;
else if ( !strcmp( argv[2], "toggle" ))
function=2;
else {
fprintf( stderr,
"lockkeys: function must be on, off, or toggle
" );
exit( 1 );
}
if ( !strcmp( argv[1], "numlock" ))
key=NUMLOCK;
else if ( !strcmp( argv[1], "capslock" ))
key=CAPSLOCK;
else if ( !strcmp( argv[1], "scrolllock" ))
key=SCROLLLOCK;
else {
fprintf( stderr,
"lockkeys: key must be numlock, capslock, or scrolllock
" );
exit( 1 );
}
if ( ioctl( RDFD, KDGETLED, &c ) != 0 ) {
perror( "lockkeys: can't get current lock state" );
exit( 2 );
}
if ( function == 0 )
c &= ~key;
else if ( function == 1 )
c |= key;
else
c ^= key;
if ( ioctl( RDFD, KDSETLED, c ) != 0 ) {
perror( "lockkeys: error setting lock state" );
exit( 2 );
}
exit( 0 );
}
注:该程序非我原创,来自SCO网站,该程序不能在Xwindow中使用仅支持控制台模式。
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/