You are not logged in.
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
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"
fiBut 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
Is there any reason you don't just change the global typematic delay and rate instead of looking for a bash/openbox specific solution?
Offline
^ my thought too.
xset r offwill turn autorepeat off (and of course you can then switch it back on with 'xset r on').
Offline
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
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
"xset -r" actually takes a keycode as optional parameter, eg.
xset -r 123to 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
This is exactly what I need. Thank you very much for your help !
Offline