Giter Club home page Giter Club logo

touchemulator's Introduction

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 the Emulator() 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.

<script src="touch-emulator.js"></script>
<script> TouchEmulator(); </script>
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 the mousedown, 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;

  • assert_true: event is a TouchEvent event expected true got false
    • We trigger an event of the type Event
  • assert_equals: touch list is of type TouchList expected "[object TouchList]" but got "[object Array]"
  • assert_equals: touch is of type Touch expected "[object Touch]" but got "[object Object]"

Bookmarklet

javascript:!function(a){var b=a.createElement("script");b.onload=function(){TouchEmulator()},b.src="//cdn.rawgit.com/hammerjs/touchemulator/0.0.2/touch-emulator.js",a.body.appendChild(b)}(document);

Options

TouchEmulator.template = Function(touch)

Change the css properties of the rendered touches.

TouchEmulator.multiTouchOffset = 75

The distance between the two touch points when entering the multi-touch zone.

touchemulator's People

Contributors

jtangelder avatar voronianski avatar irae avatar

Watchers

James Cloos avatar sbrilenko avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.