This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two-finger right-click and zoom with a touch screen
I recently got a new touchscreen, and was upset that I couldn't get multi-touch to work on it. After some research, I discovered a program called "twofing" which gives two-finger right-click and two-finger zoom. I've created a how-to for you guys.

Credit to JimmyN on I made this a bit more generic, from his original post:

This modification will give two-finger right-click and two finger zoom. It does work on OpenCPN and on the web browser. I used the latest update of OpenPlotter with the most recent updates of Stretch.

First we'll need to fetch the files, I created a temp directory to work in, and afterward it can be deleted. So open a terminal and get started.

mkdir ~/temp
cd ~/temp

That should report that "twofing-0.1.2.tar.gz" was saved.

Now we'll add some needed packages, if any of these are already installed it's OK. We'll update first, and then install them with the following commands.

sudo apt-get update
sudo apt-get install build-essential libx11-dev libxtst-dev libxi-dev x11proto-randr-dev libxrandr-dev

Now that those are in place we can extract the downloaded file and compile the binary using "make".

tar -xvzf twofing-0.1.2.tar.gz
cd twofing-0.1.2

It that is successful,

make install

This will do a few things. It will put a new executable called "twofing" into "/usr/bin/". It will also place a new file in "/etc/udev/rules.d" called "70-touchscreen-egalax.rules". We'll do some editing on that one in a moment.

Now, we need to discover the name of the multi-touch display you are using, and the USB ID. From your display (not from a remote terminal) run:


Mine looked like this:

pi@openplotter:~ $ xinput
⎡ Virtual core pointer                          id=2 [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4 [slave  pointer  (2)]
⎜   ↳ Logitech K400                             id=9 [slave  pointer  (2)]
⎜   ↳ G2Touch Multi-Touch by G2TSP              id=8 [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3 [master keyboard (2)]
    ↳ Virtual core XTEST keyboard               id=5 [slave  keyboard (3)]
    ↳ C-Media Electronics Inc. USB Audio Device id=6 [slave  keyboard (3)]
    ↳ Logitech K400

The name of my touch pointer is "G2Touch Multi-Touch by G2TSP". Yours may vary. Save this name, whatever it is.

Next, you need the USB ID of your pointer. Run:


Mine looked like this:

Bus 002 Device 002: ID 174c:0857 ASMedia Technology Inc. 
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 011: ID 2a94:564d  
Bus 001 Device 010: ID 148f:5370 Ralink Technology, Corp. RT5370 Wireless Adapter
Bus 001 Device 009: ID 1546:01a7 U-Blox AG [u-blox 7]
Bus 001 Device 008: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 007: ID 0bda:2838 Realtek Semiconductor Corp. RTL2838 DVB-T
Bus 001 Device 006: ID 0d8c:0014 C-Media Electronics, Inc. Audio Adapter (Unitek Y-247A)
Bus 001 Device 005: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port
Bus 001 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
Bus 001 Device 002: ID 2109:3431 VIA Labs, Inc. Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

It took a little trial and error, but I discovered that the one unnamed USB device is actually my touch device. Yours might have a name. What you want is the USB ID for it, which in my case is "2a94:564d". You'll also need this info.

Next we are going to edit the file that was installed when you did "make install" above. The name of the file isn't important, the number at the beginning is. I just left mine with "egalax" in the name, even though I don't have an egalax touch controller.

Edit the file with:

sudo nano /etc/udev/rules.d/70-touchscreen-egalax.rules

It's going to look like this when you open it:

SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0eef",ATTRS{idProduct}=="480d",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
SUBSYSTEMS=="usb",ACTION=="add",KERNEL=="event*",ATTRS{idVendor}=="0486",ATTRS{idProduct}=="0186",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"
KERNEL=="event*",ATTRS{name}=="eGalaxTouch Virtual Device for Multi",SYMLINK+="twofingtouch",RUN+="/bin/chmod a+r /dev/twofingtouch"

The first line and the last line need to be edited with the information you collected previously with xinput and lsusb. On the first line, replace the "idVendor" identifier with the first part of the USB ID you collected with lsusb (the part before the ":") and the "idProduct" identifier with the second part (the part after the ":").

On the last line, replace the "ATTRS{name}" part with the touch controller name you got when you did xinput.

The second line in this file is for another touch controller. I'm not sure why it's there, but it doesn't hurt anything. I suppose if someone were ambitious they could create a "one file to rule them all" file that would identify all touch controllers.

EDIT: it turns out, all you need is the USBID. I commented out the last two lines and mine still works fine.

You are done with this file. Save with CTRL-X, Y.

Now reboot and then we can give it a test.
Test it using the debug switch. If you have no errors you'll get a calibration screen, press <CTRL> C to exit.
twofing --debug

If that went OK then start twofing again, without the debug switch, and touching two fingers on the window titlebar should give you a "right click" dropdown menu.

Now you'll probably want to start it up when the desktop starts, so let's add it to the autostart file. In the original instructions they identified a file in ~/.config/lxsession/LXDE-pi/ called "autostart". It wasn't there in my implementation. I editied the autostart file in "/etc/xdg/lxsession/LXDE-pi"

nano /etc/xdg/lxsession/LXDE-pi/autostart

Scroll down to the bottom and add this line.


EDIT: You may find that twofing doesn't start reliably on startup. In my case, I discovered a few second delay was needed before twofing was run. I did this with a bash script, that called twofing after delay. The script looks like this:
sleep 10
which I saved to /usr/local/bin/ You'll need to make it executable with "sudo chmod +x /usr/local/bin/

If yo do this, the entry in /etc/xdg/lxsession/LXDE-pi/autostart needs to be:


Save the change, reboot again, and it should be working. If so you can delete the /temp directory and everything in it.

rm -r ~/temp

That should do it. As I said, I now have two-finger zoom with OpenCPN, and two-finger right-click.

Forum Jump:

Users browsing this thread: 1 Guest(s)