Touch Emulator
Emulate multi-touch input on your desktop. Triggers touch events as
specified by W3C. Press the shift
key to pinch and rotate!Install
Download the script from this repo, via Bower:bower install hammer-touchemulator
or NPM:
npm install hammer-touchemulator
How to use
Include the javascript file, and call theEmulator()
function before any other libraries that do something with the
touch input. It will set some fake properties to spoof the touch detection of some libraries, and triggers touchstart
, touchmove
and touchend
events on the mouse target.
````html
````````js function log(ev) { console.log(ev); }
document.body.addEventListener('touchstart', log, false); document.body.addEventListener('touchmove', log, false); document.body.addEventListener('touchend', log, false); ````
Also, the script includes polyfills for
document.createTouch
and document.createTouchList
.How it works
It listens to themousedown
, mousemove
and mouseup
events, and translates them to touch events. If the mouseevent
has the shiftKey
property to true
, it enables multi-touch. The script also prevents the following mouse events on the page:
mousedown
, mouseenter
, mouseleave
, mousemove
, mouseout
, mouseover
and mouseup
.Web platform tests
The script has been tested with the w3c web platform tests and passes all tests, except these;- asserttrue: event is a TouchEvent event expected true got false
Event
- assertequals: touch list is of type TouchList expected "object TouchList" but got "object Array"
- assertequals: touch is of type Touch expected "object Touch" but got "object Object"