How to set keyboard shortcuts?

Using applications, configuring, problems
Message
Author
noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

How to set keyboard shortcuts?

#1 Post by noryb009 »

I have Calculator, Log Off, media buttons (play, back, next, mute, ect.) and some other buttons on my keyboard that I want to use in puppy 501. Windows automatically works with the buttons. Is there any way to use these in puppy?

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#2 Post by npierce »

First we need to see if the X server can see these keys. Use xev to do that. If you don't have xev on your Puppy, it can be downloaded here:

http://www.murga-linux.com/puppy/viewto ... h&id=12635

Open the file with pupzip, extract xev to /usr/local/bin/ and execute this command:

Code: Select all

xev
A window named "Event Tester" will appear. Press and release a letter key to see if xev is working. You should see something like this in your rxvt window:

Code: Select all

KeyPress event, serial 29, synthetic NO, window 0x1400001,
    root 0x55, subw 0x0, time 1957549319, (504,387), root:(732,634),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XmbLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False

KeyRelease event, serial 29, synthetic NO, window 0x1400001,
    root 0x55, subw 0x0, time 1957549475, (504,387), root:(732,634),
    state 0x0, keycode 38 (keysym 0x61, a), same_screen YES,
    XLookupString gives 1 bytes: (61) "a"
    XFilterEvent returns: False
If you don't see something similar, click in the "Event Tester" window and try again.

Once you have it working, try each of your special buttons. If nothing happens then I can't help you. But if they cause KeyPress and KeyRelease events, report the keycodes and keysyms, and we can probably figure out a way to make them useful.

To exit out of xev close the "Event Tester" window, or click in the rxvt window and press ctrl+c.

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#3 Post by noryb009 »

OK, most of the keys work. These include:
My Documents
Mute
Play/Pause
Stop
Volume Up
Volume Down
Skip (used in media players)
Back (used in media players)
Media
Mail
Web
Calculator
Sleep

I mostly want to use the buttons between Mute and Back.

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#4 Post by npierce »

First, I must warn you that making the buttons useful is one thing, and making them do exactly what you want is another. But let's see what we can do.

I don't have buttons like yours, but I do have keys that I can use with the Fn key to do things like mute the sound. Some, like the screen brightness keys, seem to be controlled by the BIOS, and they've always worked. I'd never tried to get the others to do anything. However, your question has inspired me!

So let's start off with Mute, Volume Up, and Volume Down.

The following works for me using JWM on Puppy 4.3.1. If you are using something else, we may need to make some adjustments.

Make a backup of /root/.jwm/jwmrc-personal then edit it to add the following lines to the list of other Key lines:

Code: Select all

<Key keycode="160">exec:amixer sset Master 0</Key>
<Key keycode="176">exec:amixer sset Master 1+,1+</Key>
<Key keycode="174">exec:amixer sset Master 1-,1-</Key>
You will need to replace my keycodes with the keycodes you obtained from xev.

Restart JWM (Menu -> Shutdown -> Restart JWM) and try out those three buttons.

Now I'm going to go experiment with some of the other keys.

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#5 Post by noryb009 »

I'm using puppy 501, which uses zmixer (I think), which doesn't support those commands,

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#6 Post by npierce »

Correct, zmixer doesn't support those commands.

I have zmixer. But I also have amixer.

If you open a terminal window and run

Code: Select all

amixer
and it spits out a list of simple mixer controls, then you have it too. If you don't have it, do you have alsamixer?

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#7 Post by noryb009 »

I guess I do have amixer.

mdev
Posts: 19
Joined: Mon 17 May 2010, 07:15
Location: Berlin

#8 Post by mdev »

There are special keysyms for these. For example, I have the following in my ~/.Xmodmap

Code: Select all

keycode 121 = XF86AudioMute NoSymbol XF86AudioMute NoSymbol XF86AudioMute
keycode 122 = XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume NoSymbol XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume NoSymbol XF86AudioRaiseVolume
keycode 208 = XF86AudioPlay NoSymbol XF86AudioPlay NoSymbol XF86AudioPlay
keycode 209 = XF86AudioPause NoSymbol XF86AudioPause NoSymbol XF86AudioPause
keycode 232 = XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown NoSymbol XF86MonBrightnessDown
keycode 233 = XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp NoSymbol XF86MonBrightnessUp
After making changes to the file, run:

Code: Select all

xmodmap ~/.Xmodmap

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#9 Post by npierce »

mdev,

Thanks for the tip about the special keysyms. Your way is certainly a better way to do this, since any application that recognizes these keysyms will then work without the need to plug in the keycodes, and once those applications are configured they will work with any keyboard that has those buttons, as long as the symbols are mapped to the keys.

My keyboard is different from yours, so I used the following for my .Xmodmap:

Code: Select all

keycode 160 = XF86AudioMute
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
keycode 162 = XF86AudioPlay XF86AudioPause
keycode 164 = XF86AudioStop
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
noryb009,

You can add the above lines to your /root/.Xmodmap file. (If that file doesn't yet exist, simply create a new one.) If the keycodes that you got from xev are different from what I have above, you will need to adjust accordingly.

Then, as mdev said, run:

Code: Select all

xmodmap ~/.Xmodmap
noryb009 wrote:I guess I do have amixer
Were you able to edit /root/.jwm/jwmrc-personal and get the mute and volume buttons working? If you are new to editing configuration files and want some help, let us know.

The following lines can be added to your /root/.jwm/jwmrc-personal to support the keys that you listed in an earlier post. The audio player controls are configured here to work with aqualung.

Code: Select all

<Key key="XF86AudioMute">exec:amixer sset Master 0</Key>
<Key key="XF86AudioRaiseVolume">exec:amixer sset Master 1+,1+</Key>
<Key key="XF86AudioLowerVolume">exec:amixer sset Master 1-,1-</Key>
<Key key="XF86AudioPlay">exec:aqualung -N 0 -L</Key>
<Key mask="S" key="XF86AudioPause">exec:aqualung -N 0 -U</Key>
<Key key="XF86AudioStop">exec:aqualung -N 0 -T</Key>
<Key key="XF86AudioPrev">exec:aqualung -N 0 -B</Key>
<Key key="XF86AudioNext">exec:aqualung -N 0 -F</Key>
<Key key="XF86Documents">exec:rox ~/my-documents</Key>
<Key key="XF86AudioMedia">exec:xmessage "Media button was pressed."</Key>
<Key key="XF86Mail">exec:defaultemail</Key>
<Key key="XF86WWW">exec:defaultbrowser</Key>
<Key key="XF86Calculator">exec:calcoo</Key>
<Key key="XF86Sleep">exec:xmessage "Sleep button was pressed."</Key>
I don't know what you want your Media button to do, so it is configured here to just bring up a test message. If you know the command that you want it to run, you can just put it where it now says xmessage '"Media button was pressed."' I did the same for your Sleep button, since I don't know what command Puppy 5.0 uses for that, or if your PC supports it properly.

If you cannot get the amixer working, you could replace the mute and volume lines with these:

Code: Select all

<Key key="XF86AudioMute">exec:aqualung -V m</Key>
<Key key="XF86AudioRaiseVolume">exec:aqualung -V +3</Key>
<Key key="XF86AudioLowerVolume">exec:aqualung -V -3</Key>
But using these lines will affect mute and volume for aqualung only, not other applications.

I've tested all this in Puppy 4.3.1. Please let us know if you need to make adjustments for Puppy 5.0, or have other questions. (And when you get it working, we'd like to hear that too!)

Good luck.

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#10 Post by noryb009 »

I can't get any of the buttons to work.

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#11 Post by npierce »

Sorry for the delay in responding. I've been away from my computer this month.

Did you remember to run xmodmap after editing /root/.Xmodmap and restart JWM after editing /root/.jwm/jwmrc-personal ?

Did you get any error messages when you ran xmodmap or restarted JWM?

What keycodes and keysyms did you get when you ran xev?

If you post the contents of your /root/.Xmodmap and /root/.jwm/jwmrc-personal files, perhaps we can figure out what has gone wrong.

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#12 Post by noryb009 »

I don't know what you want your Media button to do
It is supposed to open the a media player (like aqualung)

Anyways, I've read over the whole topic again. In my jwmrc-personal, am I supposed to have a, b, c or d?

a) <Key key="XF86AudioMute">exec:amixer sset Master 0</Key>
b) <Key key="XF86*insert key code here*">exec:amixer sset Master 0</Key>
c) <Key key="XF*insert key code here*">exec:amixer sset Master 0</Key>
d) <Key key="*insert key code here*">exec:amixer sset Master 0</Key>

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#13 Post by npierce »

noryb009 wrote:. . . am I supposed to have a, b, c or d?
a

And you will need a line like this in /root/.Xmodmap

Code: Select all

keycode 160 = XF86AudioMute
Of course, your keyboard may want a number other than 160. Use the keycode value that you got from xev.
noryb009 wrote:
I don't know what you want your Media button to do
It is supposed to open the a media player (like aqualung)
Okay, so you would use this line in jwmrc-personal

Code: Select all

<Key key="XF86AudioMedia">exec:aqualung</Key>
and a line like this in /root/.Xmodmap

Code: Select all

keycode 237 = XF86AudioMedia
Again, your keyboard may not use 237. Use the keycode value that you got from xev.

User avatar
DaveS
Posts: 3685
Joined: Thu 09 Oct 2008, 16:01
Location: UK

#14 Post by DaveS »

npierce wrote:

Code: Select all

<Key keycode="160">exec:amixer sset Master 0</Key>
<Key keycode="176">exec:amixer sset Master 1+,1+</Key>
<Key keycode="174">exec:amixer sset Master 1-,1-</Key>
Just a small thing: in line 1 above, if you use

Code: Select all

<Key keycode="160">exec:amixer sset Master toggle</Key>
Then the key will toggle mute on/off/on/off etc....
Spup Frugal HD and USB
Root forever!

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#15 Post by noryb009 »

Yes! I got it working!

The only thing is the media command keys. Does puppy 501 USE amixer, or just has it installed? If it isn't enabled by default, how do I take zmixer out and put amixer in?

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#16 Post by npierce »

noryb009,

I am glad to hear that you were successful.

As for Puppy 501, I know next to nothing, so don't know if it uses amixer or not, or if it even uses the ALSA drivers by default. Perhaps a Puppy 501 user will pop-in here to let us know.

In the meantime, from an earlier post . . .
npierce wrote:If you cannot get the amixer working, you could replace the mute and volume lines with these:

Code: Select all

<Key key="XF86AudioMute">exec:aqualung -V m</Key>
<Key key="XF86AudioRaiseVolume">exec:aqualung -V +3</Key>
<Key key="XF86AudioLowerVolume">exec:aqualung -V -3</Key>
But using these lines will affect mute and volume for aqualung only, not other applications.
DaveS,

Thanks for the tip about toggling the mute. I didn't know that could be done.

p310don
Posts: 1492
Joined: Tue 19 May 2009, 23:11
Location: Brisbane, Australia

#17 Post by p310don »

Hi guys,

I have made some great headway with the instructions in this post, but I'm stuck on making the play/pause, stop, previous and next keys do something on my media key keyboard.

I can make them do "something" by mapping the key strokes using xev and editing jwmrc-personal accordingly, but, I don't know how to make them do what they're supposed to.

I want play to play, stop to stop etc. I see the instructions for using aqualung media player, and tried to adapt those to either songbird or gnome-mplayer but with no success.

I don't understand the switches after the :aqualung. I.E.
<Key key="XF86AudioPlay">exec:aqualung -N 0 -L</Key> what are the -N 0 -L bits for? I think the -L is the key binding in aqualung, but what are the others?

I have tried using <Key key="XF86AudioPlay">exec:songbird -N 0 -space</Key> with space being the key binding for play/pause in songbird, but all this does is launch songbird, not play or pause it.

Some help would be appreciated.
Thanks
Paul

noryb009
Posts: 634
Joined: Sat 20 Mar 2010, 22:28

#18 Post by noryb009 »

the "-N 0 -L" is the way to change the song (next/last) from the command line (maybe it's another function, not sure)

try running from the console:

Code: Select all

songbird --help
It may have a command line way of next, play, etc.

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#19 Post by abushcrafter »

@p310don look at aqualungs CL parameters. In a terminal/console type: "aqualung --help".
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

p310don
Posts: 1492
Joined: Tue 19 May 2009, 23:11
Location: Brisbane, Australia

#20 Post by p310don »

@noryb009 typing songbird --help only starts songbird, it doesn't give me any cli help options. Perhaps songbird isn't controllable from the cli. Even looking at what is happening in the terminal when using songbird doesn't give me any clues as to what might be helpful.

@abushcrafter I'm not using aqualung, so can't type that in to get the cli functions.

Would I be right in the assumption that this media key support in puppy is only possible with programs that are controllable from the command line?

A quick google of songbird suggests that it is not controllable from cli, and, the only references to doing such pertain to windows support, not linux. And, it seems songbird is no longer actively supporting linux.

Interestingly, and somewhat [solved] for me, in the media player deadbeef, there is a "global hotkeys" section under preferences. I haven't been able to get that to work in the past, but now that I have filled in some info about the media keys, ie given them names, using that works perfectly for setting up the media keys.

Now I guess my next challenge RE media keys is to get them to also work in gnome-mplayer without affecting them working in deadbeef.

Perhaps this is another area where puppy could improve its automatic setup. in windows and ubuntu this stuff just works for me on this machine / keyboard. In puppy, it was more of a challenge. Does anyone know how ubuntu does it?

Post Reply