开发者

On key board handler in linux using c programing

I am trying a program in c that controls keyboard handler to blink NUMLOCK & CAPSLOCK LED's as a reaction of ctrl+alt+del push..开发者_运维技巧. please help me..


I kinda agree with KP. This is funny...

But if yer serious...

First:

There's a setleds program that might help you get started. It's been around for ages... Try man setleds.

Also, xset can be used (under X-windows) to change leds... (You may have to see which leds are enabled for changing in the X-config file.)

Second:

Detecting ctrl+alt+del is more of an issue as it's flagged specially by init. Look in /etc/inittab or /etc/init/control-alt-delete.conf or someplace like that, and you'll see lines like:

# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -h now

Or:

# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed.  Usually used to shut down the machine.

start on control-alt-delete

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

So you'd have to disable that... Or simply have it run your keyboard-blink program rather than /sbin/shutdown.

Also, watch out for "Control-Alt-Backspace" -- Many X11 config setups enable this combination to shutdown the X server. (Option "DontZap".)

Third:

Now you need to find a way to pickup the control-alt-delete keypress. It's not impossible, but it may not be as simple as getc(). (The again, I could be wrong...)

Of course, if you don't want your program to have the keyboard focus. If you want this to happen while other programs are running in the foreground with keyboard focus... Well then yer looking at tweaking the kernel or some kernel driver. (Or having inittab run yer program instead of /sbin/shutdown.)

Any way you slice it, this is not a good Hello World type exercise.


Option:

  • Find the right place to trap Alt+Ctrl+Del and register a handler.
  • Use the KDGETLED/KDSETLED ioctl on /dev/console to changes the keyboard LEDs.

Good Luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜