Enable the Use of Special Keys

How to do things, solutions, recipes, tutorials
Post Reply
Message
Author
User avatar
Dougal
Posts: 2502
Joined: Wed 19 Oct 2005, 13:06
Location: Hell more grotesque than any medieval woodcut

Enable the Use of Special Keys

#1 Post by Dougal »

Sometimes people ask here about using the "multimedia" buttons on their keyboard.

Here are a few simple steps to help you do that:

1) Find out what type of keyboard you have:
I don't have multimedia keys, but what I do have is what I thought of as a "104+3" keyboard: a pc104, with three extra keys at the top right: Power off, Sleep, Wake up.

I discovered that what I have is actually referred to as a "acpi" keyboard.
(more on this at the end of the post)

2) Set X to recognize it:
To enable such a keyboard all you need to do is go to Setup->Mouse/keyboard wizard->Advanced...

Then you select your keyboard ("acpi" in my case), press "apply" and the keys will be recognized.


3) Make the keys do something:
You will most likely want to set some key-bindings, for the keys to actually do something...

Say I want to use the "Power off" key to shut down.
There are two things I need to do:

A) Find the "name" Xorg gave the key.
Open the file /etc/X11/xkb/symbols/inet and look for your keyboard.
In my case I get:

Code: Select all

// ACPI Standard
partial alphanumeric_keys
xkb_symbols "acpi" {
    key <I5E>	{	[ XF86PowerOff		]	};
    key <I5F>	{	[ XF86Standby		]	};
    key <I63>	{	[ XF86WakeUp		]	};
};
Which shows you the keycode and the name assigned to it.
So my key is "XF86PowerOff".

B) Set the keybinding
Open /root/.jwm/jwmrc-personal and go down to the key bindings part.

You want to set the key "XF86PowerOff" to shut down. In Puppy, shutting down is done with the script "wmpoweroff" (to find out something like that, just open /root/.jwmrc and search for "power off"...).

So you just need to add a binding that makes XF86PowerOff execute that script:

Code: Select all

<Key key="XF86PowerOff">exec:wmpoweroff</Key>
That's it! Just restart JWM, so the settings will take effect.


Sidenote: If you want to know what any of the normal function keys is named, you can look in /etc/X11/xkb/symbols/pc for your keyboard layout and open it.
The layout will probably be based on /etc/X11/xkb/symbols/pc/pc, with some keys changed, so you might want to look at that one, too.

Useful example: the Win keys are Super_R and Super_L, so making them circle through the open windows is just a matter of adding:

Code: Select all

<Key key="Super_R">next</Key>
<Key key="Super_L">next</Key>
Another example: to make the "menu" key open the JWM menu:

Code: Select all

<Key key="Menu">root:3</Key>

If you can't find out your keyboard type:
The way I found out which keyboard I have was (except for looking in /etc/X11/xkb/symbols/inet for a keyboard that has only three special buttons, matching mine...) by checking the keycodes.

Here's how I did it (there is some simple GUI for doing it, but I don't remember what it's called...):
Take the "showkeys" app (attached, just gunzip it) and put it somewhere like /usr/bin.
Now exit to the prompt (important: don't try running it from X or it might cause damage).
Now run it with the "-s" option.
When it is running, you just press a key and the hex codes generated will appear. Right them down next to the key name, for use later on.
If you are lazy (like me), you can just redirect the output to a file:
Just run

Code: Select all

showkey -s >showky-output
and go over your special keys (in order!) and press each once.
Note: you cannot just kill showkey -- it terminates on its own if you don't press any key for 10 seconds.

Ok, now that you're done with that, start X again and look at the showky-output file. In my case:

Code: Select all

0x9c 
0xe0 0x5e 0xe0 0xde 
0xe0 0x5f 
0xe0 0xdf 
0xe0 0x63 0xe0 0xe3
The first (0x9c) will always be there -- probably from "enter" being released.
The second line corresponds to me pressing (0xe0 0x5e) and releasing (0xe0 0xde) my "Power off" key.
Next we have pressing and releasing the "Sleep" button. I must have delayed longer before leaving the "sleep" button, as releasing it is in a separate line.

You can see the pattern of how it is displayed:
- Each key generates codes when pressed and released.
- Special keys seem to be preceded by "0xe0"

What you are interested in will be the second part of each key press: 0x5e, 0x5f, 0x63.

Now, compare those codes with what you see in /etc/X11/xkb/symbols/inet:

Code: Select all

key <I5E>	{	[ XF86PowerOff		]	};
key <I5F>	{	[ XF86Standby		]	};
key <I63>	{	[ XF86WakeUp		]	};
And you can see that "0x5e" matches "I5E" ("I" for internet), "0x5f" "I5F" etc.

Now you just need to look through that file and find a keyboard that matches your buttons.
Attachments
showkey.gz
(3.06 KiB) Downloaded 1119 times
What's the ugliest part of your body?
Some say your nose
Some say your toes
But I think it's your mind

User avatar
CatDude
Posts: 1563
Joined: Wed 03 Jan 2007, 17:49
Location: UK

#2 Post by CatDude »

Hi All

I have found the following line of code very useful, when it comes to identifying keys.
Its a lot easier to read,than if you just entered xev.

Code: Select all

xev | grep -A2 --line-buffered '^KeyRelease' | sed -n '/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p'
Then press each key (with the cursor over the little box)
(you may have to give the mouse wheel a wiggle about over the window AFTER each key press, to be able to see the result)

You will get similar to below:

232 NoSymbol
223 XF86Standby
153 NoSymbol
144 NoSymbol
178 NoSymbol
164 NoSymbol
162 NoSymbol
161 NoSymbol
160 XF86AudioMute
174 XF86AudioLowerVolume
176 XF86AudioRaiseVolume

REMEMBER TO KEEP NOTE of what belongs to what.

CatDude
[img]http://www.smokey01.com/CatDude/.temp/sigs/acer-futile.gif[/img]

georgeeejacob
Posts: 38
Joined: Fri 06 Jul 2007, 11:48

#3 Post by georgeeejacob »

How to take control of a key press event in puppy linux 2.16 and handle it to do nothing...

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#4 Post by Pizzasgood »

If just leaving the command field blank didn't work, I suppose you could just give it a pointless command, like echo "queso" > /dev/null
That just sends the word "queso" (Spanish for cheese) to the /dev/null file, which is equivalent to dumping it into a black hole, or possibly my mouth (except less filling).
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Windows Key

#5 Post by ecomoney »

Would it be possible to get the "windows" key (yuk!!!) to open the jwm or icewm start menu?
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
alienjeff
Posts: 2265
Joined: Sat 08 Jul 2006, 20:19
Location: Winsted, CT - USA

#6 Post by alienjeff »

@ecomoney:

In re: JWM, yes. Ahem. Read Dougal's excellent How-To (the first post of this thread).

Or if you prefer stunted edification, add this line to your jwm-personal file:

Code: Select all

<Key key="Super_L">root:1</Key>     <!-- left hand Windows key - call up Menu button -->
[size=84][i]hangout:[/i] ##b0rked on irc.freenode.net
[i]diversion:[/i] [url]http://alienjeff.net[/url] - visit The Fringe
[i]quote:[/i] "The foundation of authority is based upon the consent of the people." - Thomas Hooker[/size]

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

Instant Edification

#7 Post by ecomoney »

Hi AJ

:oops: Yes I should have read that, I scan read it for "windows key" but it doesnt appear. Anyway, I added your suggestion to the bottom of my "/root/.jwm/jwmrc-personal" file, is this the one you meant?

I also tried adding

Code: Select all

<Key key="Menu">root:3</Key>
I selected menu>shutdown>restart jwm in between each change but nothing is happening. Im a lot more used to icewm, is this what I need to do?

I would also like to change the order of the alt-tab sequence to return back through the last window that has the focus, not cycle through them in order, like icewm.

Thanks for your help AJ, Ive attached a zipped copy of my jwmrc-personal file.
Attachments
jwmrc-personal.zip
(698 Bytes) Downloaded 746 times
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
alienjeff
Posts: 2265
Joined: Sat 08 Jul 2006, 20:19
Location: Winsted, CT - USA

#8 Post by alienjeff »

@ecomoney:

I have no experience with configuring iceWM. Though I've tried that WM in a few other distros, it doesn't impress me so I haven't bothered to study it. My WM of choice is Joe's which suits my needs well. My version of choice is 2.12, which pre-dates the XDG menu system of later Puppies, so any config and paths I mention for JWM reflects the pre-XDG file structure.

I've attached my ~/root/.jwm/jwmrc-personal file for your perusal and possible plagiaristic pilferage. It's heavily commented, so should be relatively self-explanatory.

As for a "reverse ALT-TAB" function, I don't know how to do that. Have you checked Joe's website?

Hope you find and use some goodies from the jwmrc-personal file.

-aj
Attachments
jwmrc-personal.zip
(1.29 KiB) Downloaded 804 times
Last edited by alienjeff on Thu 18 Oct 2007, 04:14, edited 1 time in total.
[size=84][i]hangout:[/i] ##b0rked on irc.freenode.net
[i]diversion:[/i] [url]http://alienjeff.net[/url] - visit The Fringe
[i]quote:[/i] "The foundation of authority is based upon the consent of the people." - Thomas Hooker[/size]

User avatar
ecomoney
Posts: 2178
Joined: Fri 25 Nov 2005, 07:00
Location: Lincolnshire, England
Contact:

#9 Post by ecomoney »

Thanks AJ, plauguristic pilferation is what makes linux great, and together with stunted edification, is what makes puppy linux great ;-) :D

I will make sure all contributions to 3.03ce are correctly attributed to their discoverer :wink:
Puppy Linux's [url=http://www.murga-linux.com/puppy/viewtopic.php?p=296352#296352]Mission[/url]

Sorry, my server is down atm!

User avatar
waweet
Posts: 16
Joined: Sat 20 May 2006, 08:16
Location: Koper, Slovenia

#10 Post by waweet »

i want to use increase and decrease buttons on my keyboard and in icewm it does aumix -v 0
what is equivalent of this command in Puppy 4.2.1?
thanks

SmileDog
Posts: 8
Joined: Sat 20 Jun 2009, 15:30

Re: Enable the Use of Special Keys

#11 Post by SmileDog »

Can this be set to launch an app?

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#12 Post by Pizzasgood »

i want to use increase and decrease buttons on my keyboard and in icewm it does aumix -v 0
what is equivalent of this command in Puppy 4.2.1?
thank
I don't know if Puppy includes a program that can do it automatically. Puppy does include a program called 'setvol' that can set it to arbitrary values. It's pretty easy to write a script that uses 'setvol' to increment or decrement the volume:

Code: Select all

#!/bin/sh

#defaults
DEV=0
INC=5

#show the usage message
function usage(){
        echo "$0 [-d <device #>] <increment>
Increase the volume on device <device #> by <increment> (which may be negative)
The <device #> parameter is the same as in 'setvol', and defaults to 0."
        exit
}

#parse the parameters
[ ! "$1" ] && usage
while [ "$1" ]; do
        case "$1" in
                -h)     usage
                ;;      
                -d)     DEV=$2
                        shift
                ;;      
                *)      INC=$1
                ;;      
        esac    
        shift
done    

#get the current level
CURRENT=$(setvol $DEV | grep -o '^[0-9]*')
#calculate the new level
let 'NEW=CURRENT+INC'
#set the new level
setvol $DEV $NEW 

#print the new levels
setvol $DEV
If you save that as "/usr/local/bin/incvol" and set it executable (either with chmod +x /usr/local/bin/incvol or by right-clicking, going to properties, and ticking the executable boxes), you can run it like this to increase or decrease the volume:

Code: Select all

#increase by 5% of max:
incvol 5
#decrease by 5% of max:
incvol -5
#specifically increasing the volume on device 3 by 5%
incvol -d 3 5
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

vg1
Posts: 142
Joined: Sun 02 Dec 2007, 18:56

#13 Post by vg1 »

Waweet,

not sure what you mean by 'equivalent in Pyppy 421'? You can use icewm in any puppy, including 421. Or do you mean the equivalent keys in jwm?

Here is what I use for jwm, in jwmrc-personal:

with xvesa/xorg:

Code: Select all

<Key mask="C" key="Down">>exec:amixer set Master 6%-</Key>
<Key mask="C" key="Up">exec:amixer set Master 6%+</Key>
<Key mask="C" key="0">exec:amixer set Master 0</Key>
with xorg only:

Code: Select all

<Key key="XF86AudioLowerVolume">exec:amixer set Master 6%-</Key>
<Key key="XF86AudioRaiseVolume">exec:amixer set Master 6%+</Key>
<Key key="XF86AudioMute">exec:amixer set Master 0</Key>
In /.icewm/keys:

with xvesa/xorg:

Code: Select all

key "Ctrl+KP_Divide"	amixer set Master 6%-
key "Ctrl+KP_Multiply"	amixer set Master 6%+
key "Ctrl+0"	amixer set Master 0
with xorg only:

Code: Select all

key "XF86AudioLowerVolume"	amixer set Master 6%-
key "XF86AudioRaiseVolume"	amixer set Master 6%+ 
key "XF86AudioMute"		amixer set Master 0
It works fine. You can vary the pct to your taste, of course.
The only inconvenience is that there is no 'unmute' to the previous level. Instead you have to increase the vol manually,

Is this what you meant?

vg

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#14 Post by Pizzasgood »

I didn't know you could use amixer like that. Cool. :)

You can mute/unmute with it like this:

Code: Select all

amixer set Master toggle
You can also use off and on instead of toggle if you want to specifically do one of them.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

vg1
Posts: 142
Joined: Sun 02 Dec 2007, 18:56

#15 Post by vg1 »

Yes, toggle works fine. Thanks PG.

User avatar
bignono1
Posts: 360
Joined: Sun 17 May 2009, 07:30
Location: Q8

#16 Post by bignono1 »

Edited jwm-personal file with AJ`s file but i only got the logo key to choose a page on desktop .

mcalex
Posts: 78
Joined: Sun 23 Apr 2006, 14:52
Location: Perth, WA

#17 Post by mcalex »

Dougal, aj, PG, vg; thanks for this :)

does anyone have any suggestions for the other multimedia keys? : eg how to get
  • XF86AudioPrev & XF86AudioNext to work regardless of whether gxine, aqualung, or *amp is running
    XF86Favorites, XF86HomePage and XF86Reload to work independent of the running browser
cheers & tia
mcalex

Post Reply