You are not logged in.

#1 2019-02-06 17:36:51

LithoUser
Member
Registered: 2016-11-17
Posts: 173

[solved] Temporize Openbox keybindings to improve accessibility

Hello,

I haven't found an "Accessibility" sub-forum, so I post my message here (maybe it would be a good idea to create one ?)

I have a disability that doesn't allow me to type fast on my keyboard. Sometimes I press on the keys for too long, and it's a problem when it's a keybinding, of course, since it's then repeated multiple times. Is there a way to prevent this ?

More information about my setting : I use Openbox, and have keybindings similar to the following one defined in my rc.xml file :

<keybind key="XF86AudioLowerVolume">
    <action name="Execute">
        <command>amixer -q set Master 5%- unmute</command>
    </action>
</keybind>

But sometimes, the command refers to a personal bash script, that I could modify if needed to temporize it, e.g. :

<keybind key="XF86MonBrightnessDown">
    <action name="Execute">
        <command>backlight -dec 3</command>
    </action>
</keybind>

My backlight script contains the following code :

#!/bin/dash
set -e
dir="/sys/class/backlight/intel_backlight"
current=$(cat "$dir/actual_brightness")
max=$(cat "$dir/max_brightness")
step=$(( max / 100 ))
new="$current"
if [ "$1" = "-inc" ]; then
    new=$(( current + ($2 * step) ))
fi
if [ "$1" = "-dec" ]; then
    new=$(( current - ($2 * step) ))
fi
if [ "$new" -lt 0 ]; then
    new="0"
fi
if [ "$new" -gt "$max" ]; then
    new="$max"
fi
echo "$new" > "$dir/brightness"

I have searched the web for ways to temporize bash scripts (for example, it would be nice to not allow the script to be repeated more than one every half second), but haven't found anything that I could simply use (or that was easy enough for me to understand).

Would anyone have an idea of how I could do this ?
Thanx in advance for any help,
Best regards,
LithoUser

Last edited by LithoUser (2019-02-07 06:01:36)

Offline

#2 2019-02-06 19:06:23

LithoUser
Member
Registered: 2016-11-17
Posts: 173

Re: [solved] Temporize Openbox keybindings to improve accessibility

OK, inspired by this post, I've solved my problem with my backlight script using "mkdir as an atomic operation to avoid multiple scripts running at once" and a short "sleep" to temporize the script :

#!/bin/dash
set -e
lock_dir="/tmp/.brightnessctl.exclusivelock"
#
# Use mkdir as an atomic operation to avoid multiple scripts running at once
#
if mkdir "$lock_dir"; then
    dir="/sys/class/backlight/intel_backlight"
    current=$(cat "$dir/actual_brightness")
    max=$(cat "$dir/max_brightness")
    step=$(( max / 100 ))
    new="$current"
    if [ "$1" = "-inc" ]; then
        new=$(( current + ($2 * step) ))
    fi
    if [ "$1" = "-dec" ]; then
        new=$(( current - ($2 * step) ))
    fi
    if [ "$new" -lt 0 ]; then
        new="0"
    fi
    if [ "$new" -gt "$max" ]; then
        new="$max"
    fi
    echo "$new" > "$dir/brightness"
    # Temporisation
    sleep .05
    rmdir "$lock_dir"
fi

But I hoped there'd be a more generic solution far my others keybindings. I've read things about "timeout" in bash, but haven't really understood them. Has anyone ever used this in conjunction with Openbox keybindings ?

Offline

#3 2019-02-06 19:09:50

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [solved] Temporize Openbox keybindings to improve accessibility

Is there any reason you don't just change the global typematic delay and rate instead of looking for a bash/openbox specific solution?


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#4 2019-02-06 19:53:30

ondoho
Member
Registered: 2013-04-30
Posts: 692
Website

Re: [solved] Temporize Openbox keybindings to improve accessibility

^ my thought too.

xset r off

will turn autorepeat off (and of course you can then switch it back on with 'xset r on').

Offline

#5 2019-02-06 20:45:33

LithoUser
Member
Registered: 2016-11-17
Posts: 173

Re: [solved] Temporize Openbox keybindings to improve accessibility

Thanx very much for the help.

The problem is that with xset, *everything* slows down ; but for certain keybindings (and when I want to repeat a letter), with time going, it has sometimes annoyed me.

So basically I'd like the best of both worlds : being able to avoid the fast repetition of certain scripts only... maybe with timeout ? Or maybe I'll see if I can adapt the above "lock_dir" mechanism to some other scripts (don't know if it's the good way to go... maybe "rmdir $lock_dir" should be in an exit trap to make it more robust, but my bash skills are pretty limited...)

Offline

#6 2019-02-06 21:33:04

progandy
Member
Registered: 2012-05-17
Posts: 5,322

Re: [solved] Temporize Openbox keybindings to improve accessibility

You could probably register the key binding for the "Click" event which requires you to press and release the button. key repeats normally only repeat the "press" event without "release".
Edit: Forget it, that is only for mouse buttons in openbox. sxhkd can bind to the release event, though.

Last edited by progandy (2019-02-06 21:37:52)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

#7 2019-02-06 21:59:42

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 78,659

Re: [solved] Temporize Openbox keybindings to improve accessibility

"xset -r" actually takes a keycode as optional parameter, eg.

xset -r 123

to deactivate the autorepeat for keycode 123 only.
You can query the actual keycodes by eg. running "xev -event keyboard" (but they must currently not be grabbed by openbox or anything else, so briefly move away your shortcut definition/openbox config)

Offline

#8 2019-02-07 06:01:07

LithoUser
Member
Registered: 2016-11-17
Posts: 173

Re: [solved] Temporize Openbox keybindings to improve accessibility

This is exactly what I need. Thank you very much for your help !

Offline

Board footer

Powered by FluxBB