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
  • 161
  • 1
  • 5
  • Read the comment of the following question. http://unix.stackexchange.com/questions/61319/making-the-keyboard-eject-switch-work – PaulDaviesC Jan 18 '13 at 04:59

2 Answers2

3

you can use

system ("eject");

or

fp = popen("eject", "r");
close(fp);
Mohamed KALLEL
  • 359
  • 2
  • 7
  • 22
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.