0

I need to execute differents commands respect at the time I keep pressed a mouse key.

I was looking for an alternative to XMBC in linux, I'm using xbindkeys from a time to now but what I miss from my old config is executing various commands assigned to a button respect to different delays each one. I found the scripts in xbindkeys doubleclick useful but those don't acomplish my goal. My choices then were working with bash or with guile I go with bash I left my answer below.

More answers are welcomed

1 Answer 1

0

Here is my answer, I uploaded to a repo but its a small script that takes differences between the press time and the release time here is it. there is room for improvements I noticed just now but it's bedtime, well let me now if its useful to anyone.

#!/bin/bash
# hold_n_release.sh

BASE="`dirname "$(readlink -f "$0")"`"
BUTTON=$1
DELAY=$2
PROGS=$BASE/hold_n_release.$BUTTON.commands
LOCK=$BASE/tmp/hold_n_release.$BUTTON.lock
LINES=$(wc -l < $PROGS)

if [ -z "$BUTTON" -o -z "$DELAY" -o ! -f $PROGS ]; then
  echo "Usage : hold_n_release <Button> <Delay (sec)> [release]"
  echo "put the commands on a file named $BASE/hold_n_release.<Button>.commands one per line" 
  exit
fi
EPOCH=$(date +'%s')

if [[ "$3" == "release" &&  -e $LOCK ]] ; then
  LASTTIME=`cat $LOCK`
  CHOICE=$(( (EPOCH - LASTTIME) / DELAY + 1 )) 
  # echo $CHOICE
  if [ $CHOICE -le $LINES ]; then
    exec $(sed  -n "$CHOICE{p;q}" $PROGS) &
  fi
else 
  rm -f $LOCK
  echo  "$EPOCH" > $LOCK; 
fi

It needs a file with the commands each one in a line like in the example below, the last line it's intended.

xdotool ctr+c
copyq menu

Then simple using in xbindkeysrc in the following form

#Multicommand hold
"hold_n_release.sh 8 1"
  b:8
#Multicommand release
"hold_n_release.sh 8 1 release"
  b:8 + Release

Edit: Github username

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.