Emulate touch input on your desktop

Overview

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.

Comments
  • Don't swallow touch events for form inputs.

    Don't swallow touch events for form inputs.

    TouchEmulator doesn't play nicely with form inputs (specifically text <input>s and <textarea>s): you can't click to focus them, and when they are focused, you can't move the cursor or change the selection.

    I'm not sure if this is the best fix, but it seems to work in my very limited testing.

    opened by joefreeman 6
  • Use capture phase and bump zIndex for the small touch feedback circle

    Use capture phase and bump zIndex for the small touch feedback circle

    I tested the script as bookmarklet on many mobile capable sites that use touch event, and since the small circle uses bubbling phase, it was being cancelled by some websites. By using capture phase, it works flawlessly, as I didn't find any website canceling the events during capture phase.

    Other websites that use zIndex and translate3D are able to hide the small circle. By adding zIndex:100 should help most cases.

    opened by irae 1
  • Emulating event bubble from composedPath()[0] to ev.target for DOMs inside Web Components

    Emulating event bubble from composedPath()[0] to ev.target for DOMs inside Web Components

    Hi J. Tangelder,

    Here are two changes, please take a review:

    1. For DOMs inside Web Components, it emulates event bubble from composedPath()[0] to ev.target.
    2. Adds vite as static server. Adds index.html for test manual pages.
    opened by NiuZhuang 0
  • Rotation bug in documentation example

    Rotation bug in documentation example

    Steps to reproduce this bug:

    1. Take mobile phone and open this example https://cdn.rawgit.com/hammerjs/hammer.js/master/tests/manual/visual.html
    2. Put two fingers over each other vertically, rotation will have wrong initial angle.

    In this PR this bug is fixed. Here related bug in hammer.js documentation example: hammerjs/hammer.js#1215

    opened by munrocket 0
  • Emulating event bubble for DOMs inside web components

    Emulating event bubble for DOMs inside web components

    Hi J. Tangelder,

    Here is my implementation to emulate event bubbles for DOMs inside web components. My previous solution was too simple. Please take a review.

    1. It triggers touch events from composedPath()[0] to ev.target.
    2. Adds vite as static server. Adds index.html for test manual pages.
    opened by NiuZhuang 0
  • Using with current hammerjs/webpack/modern browsers

    Using with current hammerjs/webpack/modern browsers

    To get this to work with the current hammerjs and modern browsers, I had to explicitly setup hammerjs with an inputClass designation:

    let hammertime = new Hammer(canvas, { inputClass: Hammer.TouchInput })

    Otherwise it was only recognizing pointer events and not multitouch events needed for things like pinch/rotate etc.

    opened by niedfelj 2
  • TouchStart not dispatched through shadow root (?)

    TouchStart not dispatched through shadow root (?)

    This may be related to: https://github.com/hammerjs/touchemulator/issues/2

    TouchEmulator();
    
    class Block extends HTMLElement{
    
        constructor(){
            super()				
        }				
    
        connectedCallback(){ 
            const shadowRoot = this.attachShadow({mode: 'open'});		 	
            let $div = document.createElement("div")			  	
                $div.style.width = "100px"
                $div.style.height = "100px"
                $div.style.backgroundColor = "red"
    
            shadowRoot.append($div)	  	
    
            this.addEventListener("touchstart",(e)=>{
                console.log("touch my-block")
            })
    
            $div.addEventListener("touchstart",(e)=>{
                // This handler is not called if TouchEmulator() has been called. 
                // This is only broken if attached to a shadowRoot instead of the actual element. 
                console.log("touch my-block div")
            })
        }
    }
    customElements.define('my-block',Block)
    
    opened by IanBellomy 0
  • Error on creating new TouchEvent using emulated touch event

    Error on creating new TouchEvent using emulated touch event

    Attempting to create a new TouchEvent using the provided Event as a TouchEventInit dictionary results in an error:

    ex.

    document.body.addEventListener("touchstart",(e)=>{			
        document.body.dispatchEvent(new TouchEvent("touchmove",e))
    })		
    

    ... Failed to construct 'TouchEvent': Failed to convert value to 'Touch'....

    I think this is expected based on the described test failures, but this may be a not-uncommon use case, so I thought I'd log it.

    opened by IanBellomy 0
  • Swipeleft and Swiperight

    Swipeleft and Swiperight

    I think it doesn't simulate the default 'swipeleft' and 'swiperight' gestures. I can't make it work for my swipeleft and swiperight events created in Edge Animate. Am I wrong? Are you considering adding that feature?

    opened by medeor 0
Record games and emulate a League of Legends spectator server

Neeko-Server Neeko-Server is an application that record games emulates a League of Legends spectator server to serve them to the League of Legends cli

Vivi 15 Dec 1, 2022
A javascript library for multi-touch gestures :// You can touch this

hammer.js A JavaScript library for detecting touch gestures. Installation NPM npm install --save hammerjs or Yarn yarn add hammerjs or CDN https://cdn

Hammer.js 23.3k Jan 1, 2023
Super tiny size multi-touch gestures library for the web.    You can touch this →

Preview You can touch this → http://alloyteam.github.io/AlloyFinger/ Install You can install it via npm: npm install alloyfinger Usage var af = new Al

腾讯 AlloyTeam 3.3k Dec 12, 2022
Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web

Pressure is a JavaScript library for handling both Force Touch and 3D Touch on the web, bundled under one library with a simple API that makes working with them painless.

Stuart Yamartino 2.9k Dec 29, 2022
Touch-friendly image lightbox for mobile and desktop

Touch-friendly image lightbox for mobile and desktop

Andre Rinas 938 Jan 5, 2023
Desktop App for mdSilo: Tiny Knowledge silo on your desktop.

mdSilo A mind silo for storing ideas, thought, knowledge with a powerful writing tool. built with React and Tauri. Demo Discord This is desktop app, a

D.Loh 203 Dec 27, 2022
This provides an extension integration with Docker Desktop to run k9s quickly and easily through the Docker Desktop interface.

k9s extension for Docker Desktop This provides an extension integration with Docker Desktop to allow k9s quickly and easily through the Docker Desktop

James Spurin 14 Dec 16, 2022
Tag-input - A versetile tag input component built with Vue 3 Composition API

TagInput A versetile tag input component built with Vue 3 Composition API. Please read this article to learn how to build this package step by step an

Mayank 12 Oct 12, 2022
Vue-input-validator - 🛡️ Highly extensible & customizable input validator for Vue 2

??️ Vue-input-validator demo! What is this package all about? By using this package, you can create input validators only with the help of a single di

null 14 May 26, 2022
A Bootstrap plugin to create input spinner elements for number input

bootstrap-input-spinner A Bootstrap / jQuery plugin to create input spinner elements for number input. Demo page with examples Examples with floating-

Stefan Haack 220 Nov 7, 2022
A phone input component that uses intl-tel-input for Laravel Filament

Filament Phone Input This package provides a phone input component for Laravel Filament. It uses International Telephone Input to provide a dropdown o

Yusuf Kaya 24 Nov 29, 2022
A touch slideout navigation menu for your mobile web apps.

Slideout.js A touch slideout navigation menu for your mobile web apps. Features Dependency-free. Simple markup. Native scrolling. Easy customization.

Mango 8k Jan 3, 2023
Most modern mobile touch slider with hardware accelerated transitions

Get Started | Documentation | Demos Swiper Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing

Vladimir Kharlampidi 33.7k Jan 5, 2023
A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list Examples available here: http://claude

Claudéric Demers 10.3k Jan 2, 2023
Most modern mobile touch slider with hardware accelerated transitions

Get Started | Documentation | Demos Swiper Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing

Vladimir Kharlampidi 33.7k Jan 4, 2023
jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable.

fancyBox jQuery lightbox script for displaying images, videos and more. Touch enabled, responsive and fully customizable. See the project page for doc

Jānis Skarnelis 7.2k Jan 2, 2023
noUiSlider is a lightweight JavaScript range slider library with full multi-touch support. It fits wonderfully in responsive designs and has no dependencies.

noUiSlider noUiSlider is a lightweight JavaScript range slider. No dependencies All modern browsers and IE > 9 are supported Fully responsive Multi-to

Léon Gersen 5.4k Dec 28, 2022
Most modern mobile touch slider with hardware accelerated transitions

Get Started | Documentation | Demos Swiper Swiper - is the free and most modern mobile touch slider with hardware accelerated transitions and amazing

Vladimir Kharlampidi 33.7k Jan 9, 2023
:leaves: Touch, responsive, flickable carousels

Flickity Touch, responsive, flickable carousels See flickity.metafizzy.co for complete docs and demos. Install Download CSS: flickity.min.css minified

Metafizzy 7.2k Jan 4, 2023