linux 键盘灯控制软件,LINUX下如何控制小键盘灯的亮和灭

参考下面这段代码,把它改成一个函数即可

Usage: lockkeys key on | off | toggle

/*

* Program to control the console lock keys states

*

* Build with "gcc -o lockkeys lockkeys.c"

* cp lockkeys numlock.init.string /etc/

* in /etc/inittab

* "snum::sysinit:/etc/lockkeys numlock on ;/dev/console 2>;&1"

*/

#include

#include

#include

#include

#include

#include

#include

#include

#define ERROR -1

int main( int argc, char *argv[] )

{

char c;

int function, key;

int fd; /* File descriptor for console (/dev/tty/) */

if ( argc != 3 ) {

fprintf( stderr, "Usage: lockkeys key on | off | togglen" );

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 togglen" );

exit( 1 );

}

if ( !strcmp( argv[1], "numlock" ))

key= LED_NUM;

else if ( !strcmp( argv[1], "capslock" ))

key= LED_CAP;

else if ( !strcmp( argv[1], "scrolllock" ))

key= LED_SCR;

else {

fprintf( stderr,

"lockkeys: key must be numlock, capslock, or scrolllockn" );

exit( 1 );

}

/* To be used as the fd in ioctl(). */

if ((fd = open("/dev/console", O_NOCTTY)) == ERROR)

{

perror("open");

exit(ERROR);

}

if ( ioctl( fd, 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( fd, KDSETLED, c ) != 0 ) {

perror( "lockkeys: error setting lock state" );

exit( 2 );

}

close(fd);

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值