Making the keyboard eject switch work

1

I am using Linux.My keyboard switch for ejecting the CDROM does not work though it displays an eject button on the screen. I need to make it work. I know ejecting a cdrom using system call is as simple as

ioctl(cdromfd,CDROMEJECT,0)

But I don't know how to connect the an executable that contains the above system call and the event of pressing the eject key? Or shall I rely on kernel level? If then how?

PaulDaviesC

Posted 2013-01-15T08:04:16.657

Reputation: 141

Read the comment of the following question. http://unix.stackexchange.com/questions/61319/making-the-keyboard-eject-switch-work

– PaulDaviesC – 2013-01-18T04:59:19.007

Answers

3

you can use

system ("eject");

or

fp = popen("eject", "r");
close(fp);

Mohamed KALLEL

Posted 2013-01-15T08:04:16.657

Reputation: 319

Tell me how to connect it with the button. I know how to eject it using commands and programs. – None – 2013-01-15T08:12:45.267

in the method related to your button click just call one of the suggested C code – Mohamed KALLEL – 2013-01-15T08:14:43.910

1

You have to configure e.g. your desktop environment to catch the key, and call the eject command for the correct device. No programming needed.

To find out the key-code, use e.g. the xev command.

If you don't want the Eject key to be available generally, but only in a program you made, you have to add a check for keyboard events in your event loop and check for the keycode you got from xev.

Some programmer dude

Posted 2013-01-15T08:04:16.657

Reputation: 309