Link script to specific key on keyboard? [SOLVED]

Using applications, configuring, problems
Post Reply
Message
Author
User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

Link script to specific key on keyboard? [SOLVED]

#1 Post by Mike Walsh »

Afternoon, boys & girls.

Need a little bit of advice here.

I'd like to set things up so the the 'Pause' key on my keyboard will start a specific script, but I'm unsure quite how you'd do this. I've tried using 'xmodmap', but I believe that's mostly for re-mapping keys so that one key will take over the functionality of another, so.....I don't think that's what I want.

I know there's a way of doing this, but I really don't know where to look for it.

Any advice will, as always, be very much appreciated. TIA.


Mike. :wink:
Last edited by Mike Walsh on Fri 09 Feb 2018, 20:22, edited 1 time in total.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#2 Post by jafadmin »

I think it varies depending on which WM you're talking about. I have only ever done it on JWM.

So, with JWM there is a /root/.jwm/jwmrc-personal file in xml notation that handles the key mappings:

Code: Select all

# execute the script "killwireless" when Ctl+Alt+k is pressed:
<Key mask="CA" key="k">exec:killwireless</Key>

# start browser when "internet" button on keyboard is pressed
<Key keycode="236">exec:defaultbrowser</Key>
You would need to know the keycode numbers for the special keys.


That's all I got ..

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#3 Post by Mike Walsh »

Hiya, jafa.

Ah, that's fair enough; I'm JWM all the way in any case.

I had a look at /etc/xdg/templates/_root_.jwmrc, but wasn't sure about the 'mask' lines. I tried it with the 'key' lines directly above, and nothing happened.

I'll give it another try, and let ya know what happens.

Cheers.


Mike. :wink:

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#4 Post by Mike Walsh »

Hi again, jafa.

That's fixed it; something you mentioned in your example which I forgot to add to my original attempt.

Linking to here, frenchiveruti's 'suspend' script works nicely for me in several of my Pups. As you can see, I've also taken the modern 'logout_GUI' and modified it with a 'Suspend to RAM' button.....and used this in a few older Pups that used to have the old-style Logout sub-menu in the main Menu.

I was just curious to see if suspend could be triggered directly via a single key-press, rather than bringing up the LogOut_GUI to do so. Earlier on (in /etc/xdg/templates _root_.jwmrc), I tried

Code: Select all

<Key key="Pause">/usr/sbin/suspend.sh</Key>
.....which didn't do anything. Looking at your example, I then tried

Code: Select all

<Key key="Pause">exec:suspend.sh</Key>
.....and that works beautifully, after running 'fixmenus' and re-starting 'X'. It was the 'exec:' that made the difference.....I mistakenly assumed that pointing to an executable script would automatically run it, but of course, you need to tell it to run upon the key press, don't you?

So; a single press of the Pause key now puts Pup to sleep.....and, rather than frenchiveruti said about 'waking up' with the power button, I find that in fact just tapping any key on the keyboard brings her back to life again.

I'm getting to be a right lazy bugger, I really am..! Thanks for the pointers, mate.

----------------------

Just out of curiosity, how d'you find out the 'keycodes'? Someone on LinuxQuestions mentioned xev earlier on...? I fancy trying to get the 'multimedia' keys on this new wireless keyboard working.....


Mike. :wink:
Last edited by Mike Walsh on Fri 09 Feb 2018, 21:13, edited 1 time in total.

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#5 Post by jafadmin »

Done & dusted, mate ..

User avatar
Mike Walsh
Posts: 6351
Joined: Sat 28 Jun 2014, 12:42
Location: King's Lynn, UK.

#6 Post by Mike Walsh »

jafadmin wrote:Done & dusted, mate ..
@jafadmin:-

Look at the end of my previous post. I added that bit, but didn't post it for a while; I was in the middle of doing summat else, and forgot to submit it!

Do you happen to know how you can find out keycodes for the whole keyboard? I know Pup has xev (seems to be part of Busybox), but I don't have a clue as to how you use it.....and research hasn't thrown up a lot of help, either. Even the man page doesn't really make it clear what you do with it...


Mike. :wink:

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#7 Post by jafadmin »

Try: "showkey -k" from a console. Just start it then press the key you are interested in. It will show you the Press and Release codes (which are usually the same).

"showkey" is a standard part of X

User avatar
Marv
Posts: 1264
Joined: Wed 04 May 2005, 13:47
Location: SW Wisconsin

#8 Post by Marv »

Mike Walsh wrote: Just out of curiosity, how d'you find out the 'keycodes'? Someone on LinuxQuestions mentioned xev earlier on...? I fancy trying to get the 'multimedia' keys on this new wireless keyboard working.....
I run "xev -event_mask keyboard" in terminal. To get out as it traps and displays all keys quit the little auxilliary window it opens. A bit clunky but works...
Pups currently in kennel :D Older LxPupSc and X-slacko-4.4 for my users; LxPupSc, LxPupSc64 and upupEF for me. All good pups indeed, and all running savefiles for look'n'feel only. Browsers, etc. solely from SFS.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#9 Post by MochiMoppel »

jafadmin wrote:So, with JWM there is a /root/.jwm/jwmrc-personal file in xml notation that handles the key mappings:

Code: Select all

# execute the script "killwireless" when Ctl+Alt+k is pressed:
<Key mask="CA" key="k">exec:killwireless</Key>

# start browser when "internet" button on keyboard is pressed
<Key keycode="236">exec:defaultbrowser</Key>
Hmmm... that would not be XML notation.

I recommend to use XML <!-- comments -->
Or you could use bash comments as part of the shell command:

Code: Select all

<Key mask="CA" key="k">exec:killwireless # any comment could be added here</Key>

jafadmin
Posts: 1249
Joined: Thu 19 Mar 2009, 15:10

#10 Post by jafadmin »

@MochiMoppel

You are right. I added the comments in that post for description reasons. In the actual file they don't exist ..

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#11 Post by musher0 »

Hello Mike_Walsh and all.

I would like to add, for the benefit of anyone who believes in the principle of
"freedom of window managers", that the ROX Pinboard, aka PuppyPin on Puppy,
has a hot key manager.

The difference with the jwm solution is that such hot key will be associated with an
icon on the ROX pinboard. The syntax is as follows:
[two spaces]<icon x="some number" y="some number" label="something" shortcut="hot key here">command/with/path</icon
E.g., this is the line in it for the "Root" icon that Puppies usually have at the top
left corner of their screen. I have associated to it the hot key "Ctrl-Shift-r".

Code: Select all

  <icon x="80" y="96" label="file" shortcut="Control+Shift+r">/usr/local/bin/defaultfilemanager</icon>
The regular user does not have to enter this code manually, although bash scripters
really appreciate the possibility.

All the user has to do is
-- drag the application on the desktop if it is not already there; an icon is created;
-- right-click on the icon and click "edit item";
-- a small panel appears over the icon;
-- if you wish to change the hot key, click the longish button above word "locked";
-- a small rectangle is shown at the middle of the screen;
-- now type the hot key combination
-- click "ok".
(Please see attached composite image.)
That's all.

This ROX-based solution is independent of any window manager you may use on
your Puppy. A word of warning, though: with the ROX pinboard hot keys, there often
needs to be an app on screen for them to work. I never could explain this fanciful
behavior in ROX, but it exists. It is as if the ROX hot keys will not work in a Puppy
session until a ROX window has been opened. My solution is to have at all times
the ROX window for the ~ (root) directory open on one of the desktops.

~~~~~~~~~~~~~~

Speaking of window managers, the icewm and pekwm window managers have hot
key files. That I know of! Please be aware that quite a few window managers come
with a hot-key utility or configuration file.

The syntax for icewm is very simple:
key "hot key" application
If you are using icewm, type

Code: Select all

cat ~/.icewm/keys | more
to get examples. Icewm's key combos are contained in a simple text file.

pekwm also uses a simple text file as a container for its hot keys. Its syntax is
more involved than icewm's, but still quite understandable: As an example, the
command to lauch XLock is:

Code: Select all

        KeyPress = "Ctrl Mod1 L" { Actions = "Exec xlock &" }
"Mod1" being the left Alt key. In pekwm you can define such important keys.
Pekwm users can type

Code: Select all

cat ~/.pekwm/keys | more
for more examples.

Another warning: if you have hot keys for the ROX pinboard icons and for your
window manager, the ones in the WM usually have precedence. The best way to
avoid snafus is to make sure the hot key you intend to use is only used once,
either in the ROX pinboard OR in the window manager hot key file.

~~~~~~~~~~~~~~

These warnings bring me to a dedicated utility that, IIRC ( I have not used it in a
while), usually overrides other hot key managers, either WMs or ROX, because you
launch it before them.

The xbindkeys utility has made managing hot keys a specialty. From its
web page:
xbindkeys is a program that allows you to launch shell commands with your
keyboard or your mouse under X Window. It links commands to keys or mouse
buttons, using a configuration file. It's independant of the window manager and can
capture all keyboard keys (ex: Power, Wake...).
This forum has six pages of references if you ask it to search "xbindkeys", but this
post by forum member MU is a classic, IMO.

~~~~~~~~~~~~~~

I hope this little roundup of "hot keys" solutions will help Puppy users.

BFN.
Attachments
composite.jpg
How to associate a hot key with a program icon in the ROX pinboard (aka PuppyPin).
This is a composite; the key stroke box is by default in the middle of the screen.
(110.36 KiB) Downloaded 66 times
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

Post Reply