Link script to specific key on keyboard? [SOLVED]
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
Link script to specific key on keyboard? [SOLVED]
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.
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.
Last edited by Mike Walsh on Fri 09 Feb 2018, 20:22, edited 1 time in total.
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:
You would need to know the keycode numbers for the special keys.
That's all I got ..
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>
That's all I got ..
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
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
.....which didn't do anything. Looking at your example, I then tried
.....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.
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>
Code: Select all
<Key key="Pause">exec:suspend.sh</Key>
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.
Last edited by Mike Walsh on Fri 09 Feb 2018, 21:13, edited 1 time in total.
- Mike Walsh
- Posts: 6351
- Joined: Sat 28 Jun 2014, 12:42
- Location: King's Lynn, UK.
@jafadmin:-jafadmin wrote:Done & dusted, mate ..
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.
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...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.....
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.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Hmmm... that would not be XML notation.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>
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>
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:
left corner of their screen. I have associated to it the hot key "Ctrl-Shift-r".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: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:"Mod1" being the left Alt key. In pekwm you can define such important keys.
Pekwm users can type 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:
post by forum member MU is a classic, IMO.
~~~~~~~~~~~~~~
I hope this little roundup of "hot keys" solutions will help Puppy users.
BFN.
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:
E.g., this is the line in it for the "Root" icon that Puppies usually have at the top[two spaces]<icon x="some number" y="some number" label="something" shortcut="hot key here">command/with/path</icon
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>
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:
If you are using icewm, typekey "hot key" application
Code: Select all
cat ~/.icewm/keys | more
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 &" }
Pekwm users can type
Code: Select all
cat ~/.pekwm/keys | more
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:
This forum has six pages of references if you ask it to search "xbindkeys", but thisxbindkeys 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...).
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)
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)