Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
    
Read the comment of the following question. unix.stackexchange.com/questions/61319/… –  PaulDaviesC Jan 18 '13 at 4:59
add comment

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

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

2 Answers

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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.