Distinguish Left/Right Modifier Keys in Shortcuts

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Distinguish Left/Right Modifier Keys in Shortcuts

Post by MochiMoppel »

In this topic user @greengeek discovered that he -seemingly - can create JWM shortcuts using an Alt+<key> combination that would work only when the right Alt_R+<key> is pressed. Unfortunately doesn't work this way. For JWM and ROX all Alt keys work the same.. mostly (for certain keyboard maps the right Alt key will not work at all)

Wouldn't it be nice if JWM could distinguish between the 2 available Alt keys? Well, it is possible with a trick and - at least for me - it works nicely.

So far I used to invoke my favorite console rxvt with the shortcut Alt+C. My file /root/.jwm/jwmrc-personal contained the line

Code: Select all

<Key key="C" mask="A">exec:rxvt</Key>

Instead of calling rxvt directly, I now call a script, which I named key_ALT_C:

Code: Select all

<Key key="C" mask="A">exec:/path/to/key_ALT_C</Key>

The script:

Code: Select all

#!/bin/ash
# to be invoked with Alt+C shortcut (JWM or ROX)
# or by clicking on ROX icon with Alt key(s) pressed
for ID in $(xinput | sed -r '/slave *keyboard/!d;/hotkeys|webcam|button|virtual|video/Id;s/.*=([0-9]+).*/\1/'); do
    case  $(xinput query-state $ID | grep '=down') in
        *64*108*)   exec lxterminal ;;  # Alt_L+Alt_R
        *64*)       exec rxvt       ;;  # Alt_L
        *108*)      exec urxvt      ;;  # Alt_R
    esac
done
# Default if run by clicking on ROX icon without pressing any Alt key:
exec defaultterminal

The script tries to find out the ID of my keyboard (discussed in viewtopic.php?t=10250 ), then checks if the left Alt key (keycode 64), the right Alt key (keycode 108) or both are pressed. This means I can run 3 different terminal emulators, depending on which Alt key I pressed, and use only 1 JWM shortcut.

The script works the same when creating a ROX desktop icon for it. In this case I could run even 4 different commands because clicking on the icon without pressing any Alt key provides another option.

Last edited by MochiMoppel on Sat Feb 15, 2025 3:12 am, edited 1 time in total.
User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Run 3 different commands with only 1 shortcut

Post by greengeek »

Nice. Thanks for this.
I think my best use for this technique would be to select between the multiple text editors I like to use, or the multiple browsers I switch between.
Very clever! :thumbup:

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Run 3 different commands with only 1 shortcut

Post by greengeek »

Does the same limitation apply when jwm sees "CTRL" presses? (ie: That it assigns the same function to Ctrl+L and Ctrl+R ?)

If so - I assume your technique could be applied there as well?

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Distinguish Left/Right Modifier Keys in Shortcuts

Post by MochiMoppel »

greengeek wrote: Fri Feb 14, 2025 8:26 am

Does the same limitation apply when jwm sees "CTRL" presses?

Yes. But be careful. Ctrl+<key> patterns should remain reserved for application shortcuts. On the other hand system wide shortcuts should contain the Alt key. So I recommend that you use Ctrl+Alt+<key> combinations.
If you want to use all possible left/right Ctrl and Alt combinations, you will end up with 9 different choices, and if you further add the Shift key it will be 27. To master all these choices it takes the brain of a genius and the hand of a pianist - or a monkey.

I find all keys on the right side of the keyboard hard to use. That's why I prefer to create shortcuts that I can "handle" with my left hand while holding the mouse with the right. However for rarely used choices the left/right modifier key acrobatic can be quite useful.

A much more convenient way to squeeze more than 1 choice out of a single shortcut is the doubleclick method. That's a doubleclick on a key (not a mouse button!), e.g. Alt+Z fires application A and Alt+ZZ fires application B. Very easy to use but requires a different script. A bit off topic here.

BTW: ROX icon shortcuts are so much easier to change and faster to edit. I'm starting to turn away from JWM shortcuts. No more hassle with jwmrc-personal and jwm -restart
When using "iconless" shortcuts (all but the last row in the screenshot), they take little space on the desktop and can show the necessary key combination in their labels. Well, they all have icons, but 1px icons are virtually invisible.

ROX_desktop_shortcuts.png
ROX_desktop_shortcuts.png (17.16 KiB) Viewed 608 times
User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Distinguish Left/Right Modifier Keys in Shortcuts

Post by greengeek »

MochiMoppel wrote: Sun Feb 16, 2025 4:22 am

BTW: ROX icon shortcuts are so much easier to change and faster to edit. I'm starting to turn away from JWM shortcuts. No more hassle with jwmrc-personal and jwm -restart
When using "iconless" shortcuts (all but the last row in the screenshot), they take little space on the desktop and can show the necessary key combination in their labels. Well, they all have icons, but 1px icons are virtually invisible.

ROX_desktop_shortcuts.png
ROX_desktop_shortcuts.png (16.86 KiB) Viewed 497 times

Could you elaborate on what exactly "Rox icon shortcuts" are please? Are they simply desktop icons? So these are created by dragging a utility/programme to the desktop, then dragging an icon to it?
How did you get the image displayed above? Is that an icon or some sort of popup? (or "panel"?)
I struggle with this stuff. (Particularly since I have no savefile so I don't retain changes - which means I need to script such things into a .pet if possible...)

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Distinguish Left/Right Modifier Keys in Shortcuts

Post by MochiMoppel »

greengeek wrote: Tue Feb 18, 2025 5:47 am

Could you elaborate on what exactly "Rox icon shortcuts" are please?

Right click any icon, either one on the ROX pinboard or on a ROX panel. In the dialog select "Edit item". At the bottom you will find "The keyboard shortcut is:"
Click and type the desired key combination for your shortcut. When finished, press OK. That's it.
Instead of clicking the icon with the mouse you can now use the keyboard shortcut.

How did you get the image displayed above?

Took a screenshot.
Yes, my desktop background is black, no wall paper. Good for my eyes, but disqualifies me for the "Show us your desktop" beauty contest.

Is that an icon or some sort of popup? (or "panel"?)

"That" are 9 desktop icons with labels beneath. 5 of these icons can be triggered with keyboard shortcuts, 3 icons are 16x16px mini icons, all others are 1px icons, which means I have to click on the labels if I want to trigger them with the mouse (which of course I seldom do. I prefer the keyboard)

I struggle with this stuff. (Particularly since I have no savefile so I don't retain changes - which means I need to script such things into a .pet if possible...)

I also have no savefile. I don't use PuppyPin and load a ROX default pinboard via startup script. If you use JWM shortcuts you also have to "retain changes" somehow. How do you do this now?

User avatar
greengeek
Posts: 1549
Joined: Thu Jul 16, 2020 11:06 pm
Has thanked: 651 times
Been thanked: 228 times

Re: Distinguish Left/Right Modifier Keys in Shortcuts

Post by greengeek »

MochiMoppel wrote: Wed Feb 19, 2025 12:33 pm

I also have no savefile. I don't use PuppyPin and load a ROX default pinboard via startup script. If you use JWM shortcuts you also have to "retain changes" somehow. How do you do this now?

Ordinarily I don't retain any changes at all - unless for some specific reason I decide to build them into an adrv or ydrv (depending on the pup and how often I use it). I seldom use JWM shortcuts but when I do (such as the Leafpad lineup/dwn mod) I make up a script to add the necessary lines into jwmrc-personal. Then I use a pet to install it.
So the mods are only retained for that session.
I am not very good at doing "in place" file modifications - I have not learned how to use "soaping" so I just kludge my way through with sed and awk etc.

User avatar
MochiMoppel
Posts: 1343
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 521 times

Re: Distinguish Left/Right Modifier Keys in Shortcuts

Post by MochiMoppel »

greengeek wrote: Sun Feb 23, 2025 6:01 am

I seldom use JWM shortcuts but when I do (such as the Leafpad lineup/dwn mod) I make up a script to add the necessary lines into jwmrc-personal. Then I use a pet to install it.

A pet? No wonder that you seldom use JWM shortcuts :lol:
This sounds extremely complicated and total overkill. Here is not the place to discuss better ways to achieve your goal, but one option comes to mind that requires close to no coding: keep a local copy of jwmrc-personal outside of Puppy. After start-up run a one-liner to symlink /root/.jwm/ jwmrc-personal to your local copy. In principle that's what @mikewalsh did (or still does?) with his "portables".

I have not learned how to use "soaping"

There is not much to learn. You fill in some blanks with the specifics of the desktop icon you want to create (application it should run, shortcut, label, icon path etc.), save it as a script and that's about it.

Post Reply

Return to “Programming”