Skip to content

touch-ctl

Reversibly enable and disable the touchscreen. Designed for devices with a cracked screen suffering from ghost touch (phantom touches), but useful in any scenario where you want to guarantee the screen only responds to your command (via SSH) and not to physical noise.

Requires root

Manipulates character device nodes in /dev/input/eventN via mknod + rm.

Basic usage

touch-ctl status              # touch enabled or disabled?
touch-ctl off                 # disable (saves everything to restore)
touch-ctl on                  # re-enable
touch-ctl off --name NAME     # if your touch is not called "touchpanel"
touch-ctl --help

How it works (and why it's safe)

Older versions of this script simply did mv /dev/input/eventN ~/event_touch. That works, but if the /data partition is wiped or /dev/input is recreated by boot, the file disappears and the touch is "lost". The current version does it differently:

flowchart TD
    A[touch-ctl off] --> B[Find touchscreen in /sys/class/input]
    B --> C[Read major:minor from sysfs]
    C --> D[Pre-flight: mknod on temp file]
    D --> E{mknod works?}
    E -- no --> F[Abort: nothing was changed]
    E -- yes --> G[Remove the /dev/input/eventN node]
    G --> H[Android notices via inotify\nInputReader drops the device]
    H --> I[Touch disabled]
    I --> J[touch-ctl on\nRecreate node via mknod\nwith major:minor from sysfs]

Key points:

  1. The device still exists in the kernel — only the node in /dev/input is removed. The kernel still sees it at /sys/class/input/event*/device/.
  2. Pre-flight mknod test: before removing the real node, the script proves it can recreate it by creating a temp file. If that fails, aborts before touching the real node.
  3. Self-restoration: if off fails after removing the node, an EXIT trap tries to recreate it automatically.
  4. State file: /data/local/tmp/touch-ctl.state stores EVENT, DEVNUM, MODE, OWNER, and a timestamp — for manual restoration if everything goes very wrong.

touch-ctl recognizes the name it was invoked with. Create shortcuts to use as separate commands:

ln -s touch-ctl touch-off
ln -s touch-ctl touch-on
ln -s touch-ctl touch-status
# now: touch-off, touch-on, touch-status work directly

Also recognizes old names: desativar-touch, ativar-touch.

--name for different hardware

The touchscreen name in sysfs varies by manufacturer. Default is touchpanel (common on Unisoc/Samsung Go). If not found:

touch-ctl status
# prints: "device 'touchpanel' not found"
# lists all /sys/class/input/event*/device/name entries

Look in the list for your touch name (e.g. fts_ts, goodix_ts, nt36672a_ts, sec_ts) and use:

touch-ctl off --name fts_ts

Make it persistent with the TOUCH_NAME env var:

echo 'export TOUCH_NAME=fts_ts' >> ~/.bashrc
source ~/.bashrc
touch-ctl off    # now without --name

Exit codes

Code Meaning What to do
0 success —
1 operation failed (mknod, rm, etc.) see message; try touch-ctl on
2 invalid usage (bad argument) touch-ctl --help
3 no root Magisk → Superuser → Termux
4 touch not found in /sys/class/input use --name

Recovery if the screen doesn't respond

After touch-ctl off, the device only responds to a physical keyboard or SSH until you run touch-ctl on (or until reboot — /dev/input is recreated on boot, so touch comes back).

ALWAYS have one of these ready before using off:

  1. SSH running in Termux (sshd or tmux + active session);
  2. ADB connected (adb shell from a PC);
  3. Physical keyboard via OTG/Bluetooth;
  4. AnyDesk/Scrcpy accessible from another machine.

If none of those is available and touch is off, reboot the device (hold power ~10 s) — boot recreates the node and touch returns.

Migration from the old method

If you used the old version (which moved the node to ~/event_touch), the new touch-ctl on detects the legacy file, uses it as fallback for restoration, then removes it — transparent migration.

Files

Path What
/sys/class/input/event*/device/name Input device names (read)
/sys/class/input/event*/dev major:minor (read)
/dev/input/eventN Char device node manipulated
/data/local/tmp/touch-ctl.state Saved state for restoration
~/event_touch Legacy (old method, migrated and removed)

Environment variables

Variable Default What
TOUCH_NAME touchpanel Touchscreen name in sysfs
TOUCH_SYS_INPUT /sys/class/input sysfs input root
TOUCH_DEV_INPUT /dev/input Device node root
TOUCH_STATE /data/local/tmp/touch-ctl.state State file
TOUCHCTL_COLOR auto 1 forces colors, 0 disables

See also