Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
EjectCD - How to bind keycode to 'eject /dev/cdrom'?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
cord
Apprentice
Apprentice


Joined: 28 Apr 2007
Posts: 210

PostPosted: Sat Oct 19, 2013 7:53 pm    Post subject: EjectCD - How to bind keycode to 'eject /dev/cdrom'? Reply with quote

Hello All,
I have laptop with CD. That CD ejects with key located on keyboard. It works outside the system (for example - when in BIOS menu), but not in Gentoo.
xev shows keycode '178' of that key. But xmodmap corresponds that there's no function:
Code:

localhost # xmodmap -pke
----cut-----
keycode 177 = XF86Phone NoSymbol XF86Phone NoSymbol XF86Phone
keycode 178 =
keycode 179 = XF86Tools NoSymbol XF86Tools NoSymbol XF86Tools
----cut----
localhost #

How can I bind this '178' key to command:
Code:

$ eject /dev/cdrom

?
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 880
Location: Montréal

PostPosted: Sat Oct 19, 2013 10:58 pm    Post subject: Reply with quote

Code:
echo -n 'keycode 178 = XF86Eject' > ~/.Xmodmap
xmodmap ~/.Xmodmap

The problem is for me it do not work. The tray stay close after pressing the key. The eject command work.
_________________
Paul
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 880
Location: Montréal

PostPosted: Sun Oct 20, 2013 1:02 am    Post subject: Reply with quote

I found a solution. First you can activate some optional USE flags for xbindkeys like guile and tk
Code:
echo -n 'x11-misc/xbindkeys guile tk' >> /etc/portage/package.use

and than
Code:
emerge -av xbindkeys

After that in your user account execute the command
Code:
xbindkeys --defaults > $HOME/.xbindkeysrc

Edit $HOME/.xbindkeysrc and add the lines
Code:
"eject /dev/cdrom"
m:0x0 c:178

and start xbindkeys
Code:
xbindkeys

Pressing the key associate with the X keycode 178 should eject the cdrom if it is what xev show for it. "eject -r" is for the cdrom and "eject" alone is "eject /dev/cdrom" by default.

The command
Code:
xbindkeys -k

show you an example of what can be write in .xbindkeysrc for the key you press. I found Xbindkeys is simple to understand, efficient and for sure usefull. It is now start by default with X from my .xinitrc.
_________________
Paul
Back to top
View user's profile Send private message
cord
Apprentice
Apprentice


Joined: 28 Apr 2007
Posts: 210

PostPosted: Wed Oct 23, 2013 2:11 pm    Post subject: Reply with quote

Oh, thanks. But it will work only under X.org, right?
Is it possible to set system wide option? maybe some way to find 'scancode' of that key and bind it to the appropriate command :?:
Back to top
View user's profile Send private message
Logicien
l33t
l33t


Joined: 16 Sep 2005
Posts: 880
Location: Montréal

PostPosted: Thu Oct 24, 2013 5:07 am    Post subject: Reply with quote

Yes, it will only work in X.

If you want to associate a command to a console key, first you have to find the keycode of the key in a root console session with the command showkey.

If the key do not have a keycode, you have to associate a free keycode (128 to 255 are generally free) to it's scancode with the command setkeycodes. The getkeycodes command show the keycodes in use and the scancode each are associated with. The dumpkeys command show what each keycode do.

Pressing a key who do not have a keycode should print a kernel message where Linux complain about that, showing at the same time the scancode of the key. You can see it with the dmesg command.

Than create a file, for exemple cdrom.keymap, with this contain
Code:
keycode xx = F99
string F99 = "eject /dev/cdrom"

where xx is the keycode number of the key. The F99 string identifier is optional. You can see the different alphanumeric strings identifiers and their values to help you to create a new one with the command
Code:
dumpkeys --funcs-only | less

Than
Code:
loadkeys cdrom.keymap


When you press the key, the value of the string bind to it is copied after the prompt and you can press Enter to execute it.

That's all I have been able to do. I have'nt find a way for an automatic execution when the key is press and it only work during a Shell session. Out of the Shell, there's nothing to interprete the command. If someone know how to make automatic execution and out of the Shell, I am open.
_________________
Paul
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum