3

I'm using lubuntu. I want to add a shortcut to toggle (turn on and off) my touchpad.

I know I need to edit the xml file in ~/.config/openbox (in my case it's lubuntu-rc.xml) as described here and here

I want it to trigger it when Fn and F5 are pressed (on my dell there is a touchpad icon on it, so I assume it triggers also a x86 keybind, dunno if that matters)

on my machine

 synclient TouchPadOff=1

turns off the touchpad, and

  synclient TouchPadOff=0

turns it on again.

The command

synclient

without any options, returns this list

Parameter settings:
    LeftEdge = 300
    RightEdge = 1700
    TopEdge = 210
    BottomEdge = 1190
    FingerLow = 12
    FingerHigh = 15
    MaxTapTime = 180
    MaxTapMove = 107
    MaxDoubleTapTime = 180
    SingleTapTimeout = 180
    ClickTime = 100
    EmulateMidButtonTime = 75
    EmulateTwoFingerMinZ = 141
    EmulateTwoFingerMinW = 7
    VertScrollDelta = 48
    HorizScrollDelta = 48
    VertEdgeScroll = 1
    HorizEdgeScroll = 0
    CornerCoasting = 0
    VertTwoFingerScroll = 1
    HorizTwoFingerScroll = 0
    MinSpeed = 1
    MaxSpeed = 1.75
    AccelFactor = 0.0819336
    TouchpadOff = 0
    LockedDrags = 0
    LockedDragTimeout = 5000
    RTCornerButton = 2
    RBCornerButton = 3
    LTCornerButton = 0
    LBCornerButton = 0
    TapButton1 = 1
    TapButton2 = 3
    TapButton3 = 0
    ClickFinger1 = 1
    ClickFinger2 = 1
    ClickFinger3 = 0
    CircularScrolling = 0
    CircScrollDelta = 0.1
    CircScrollTrigger = 0
    CircularPad = 0
    PalmDetect = 0
    PalmMinWidth = 10
    PalmMinZ = 100
    CoastingSpeed = 20
    CoastingFriction = 50
    PressureMotionMinZ = 15
    PressureMotionMaxZ = 80
    PressureMotionMinFactor = 1
    PressureMotionMaxFactor = 1
    ResolutionDetect = 1
    GrabEventDevice = 1
    TapAndDragGesture = 1
    AreaLeftEdge = 0
    AreaRightEdge = 0
    AreaTopEdge = 0
    AreaBottomEdge = 0
    HorizHysteresis = 12
    VertHysteresis = 12
    ClickPad = 0

as you can see, there is the line "TouchpadOff = 0".

So what I'm basically asking for is someone who knows how to work grep and regular expressions to tell me how to write a shell script that reads the output of snyclient and executes "synclient TochPadOff=0" or "synclient TochPadOff=1" accordingly.

If found this script that does something very similar , but I'm struggeling on the grep part.

If found a generic toggle script , but I think grepping the info is cleaner.

I also already know how to bind a shellscript to a keyboardshortcut from that example.

help greatly appreciated .

2

This works for me:

  #!/bin/sh
  TOGGLE=$HOME/.toggle

  if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    synclient TouchPadOff=1 &
  else
    rm $TOGGLE
    synclient TouchPadOff=0 &
  fi

exit 0

There doesn't seem to be need for grep. Also, I'm not too sure that Openbox likes Fn in any rc.xml but see Nivatius' answer for how to use keypresses involving Fn. I've only ever used Super, Control, Alt, and Shift. I can bind that script to Control+Shift+F5, for example.

<keybind key="C-S-F5">        # Toggle touchpad
  <action name="Execute"><command>/home/dkb/bin/toggle-touchpad</command></action>
</keybind>
  • thanks. with xev I found the keycode for the Fn+F5 combo – Nivatius Jan 25 '16 at 12:11
1

I settled for this solution:

script

# This shell script is PUBLIC DOMAIN. You may do whatever you want with it.

TOGGLE=$HOME/.touchpadtoggle

if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    synclient TouchpadOff=1
else
    rm $TOGGLE
    synclient TouchpadOff=0
fi

config file

<!-- toggle touchpad with fn key fn+F5 -->
    <keybind key="XF86TouchpadToggle">
     <action name="Execute">
          <command>~/scripts/touchpadtoggle.sh</command>
         </action>
    </keybind>

The path in command of course, needs to point to your script

I used xev to find out the XF code of fn+F5:

run xev, press Fn key and F5 then close the popup, scroll up in the long output and look out for the keycode.

1

Here is what I placed in my ~/.config/openbox/lubuntu-rc.xml

<keybind key='XF86TouchpadToggle'>
    <action name='Execute'>
        <command>bash -c "synclient TouchpadOff=$(expr \( $(synclient | grep TouchpadOff | cut -d = -f 2) + 1 \) % 2)"</command>
    </action>
</keybind>

COMMENT
synclient (second one): lists actual parameters
grep : select the line referring to Touchpad
cut -d = -f 2 : get only the part after "="
expr \( ... + 1 \) %2 : increment by 1 and get the reminder of division by 2 (ie toggle 0/1)
synclient TouchpadOff= : set TouchpadOff to the result of above
bash -c "..." : make sure all the above is run in a bash shell.

This way I don't need a separate shell script. But you can easily put everything into a script if you prefer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.