Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Jan 15 '13 at 8:43

This question came from our site for professional and enthusiast programmers.

    
Read the comment of the following question. unix.stackexchange.com/questions/61319/… – PaulDaviesC Jan 18 '13 at 4:59

you can use

system ("eject");

or

fp = popen("eject", "r");
close(fp);
share|improve this answer
    
Tell me how to connect it with the button. I know how to eject it using commands and programs. – PaulDC Jan 15 '13 at 8:12
    
in the method related to your button click just call one of the suggested C code – Mohamed KALLEL Jan 15 '13 at 8:14

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.

share|improve this answer

You must log in to answer this question.

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