It's true, you can't detect touch or mouse devices.
But you can make assumptions.
Try this page on different devices or simulate touch/mouse events with your favorite developer tool.
touch_appmouse Presuming you don't have touch capabilities and are using a mouse (as a default fallback).
touch_app Presuming you have touch capabilities...
mouse ...but you are using a mouse.
mouse ...and you don't have or are not using a mouse.
This is a tiny* JavaScript utility that tries to presume whatever the user is interacting with a touch and/or a mouse device.
Read more on the repository page on GitHub: https://github.com/pinoceniccola/presumedevice.js
* ~480B when compressed and gzipped.