问题
I have a Raspberry Pi connected to touchscreen and running an electron app on it through the startx command,
# startx ./electron-app -- --nocursor
the problem that I can't handle the touch events like (touchstart, touchend) and apparently that is because Electron (or chromium) not seeing the screen as a touch screen.
回答1:
The problem is not that Electron/Blink isn't seeing the touchscreen / native touch events. There are two parts to the problem, as I understand it:
- You need to ensure you're receiving touch events in the OS from the touchscreen. I haven't tested with Pi/Linux, so I'm not sure if those handle touch events natively. I know that OSX, for one, requires a third-party driver like [UDPP by Touch-Base.
- Once the OS is handling touch events, those are piped through to Blink via the Electron wrapper. However, you need to set the
touch-events
command-line switch to enable it. My understanding is that that switch is passed through as a Chromium commandline switch.
I found more info on this thread, though not very much, and still haven't gotten things working on my OSX setup. Electron's documentation is very sparse...the touch-events
switch isn't even listed in their CLI docs. Hope this helps.
来源:https://stackoverflow.com/questions/40359462/electron-enable-touch-events-for-a-touch-screen