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?

1

2 Answers 2

3

you can use

system ("eject");

or

fp = popen("eject", "r");
close(fp);
2
  • Tell me how to connect it with the button. I know how to eject it using commands and programs.
    – PaulDC
    Jan 15, 2013 at 8:12
  • in the method related to your button click just call one of the suggested C code Jan 15, 2013 at 8:14
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .