Coder Social home page Coder Social logo

henrylansang / js-virtual-pointer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from miaskiewicz/js-virtual-pointer

0.0 2.0 0.0 296 KB

Emulate a human's mouse-movements using this JavaScript-based virtual pointer

HTML 85.94% JavaScript 14.06%

js-virtual-pointer's Introduction

JS-Virtual-Pointer

Emulate a human's mouse-movements using this JavaScript-based virtual pointer; the correct events will be executed in JavaScript, as if a real human was interacting on the page in a desktop or mobile browser (has support for touch events in mobile browser JavaScript implementations)

Usage

virtualpointer.move_mouse_to_element(element, length_of_mouse_movement);

virtualpointer.click_element(element);

virtualpointer.move_to_element_and_click(element, length_of_mouse_movement);

virtualpointer.run_serialized_events(array_of_events);

virtualpointer.tap_element(element); // mobile tap

virtualpointer.double_tap_element(element); // mobile double tap

virtualpointer.flick_to_element(element, length_of_flick_movement); // drag on screen to scroll to element (mobile)

array_of_events must be a serialized JSON array of events, with the following properties for each event:

  • type: type of event (e.g. mousemove, mousedown, etc.)
  • pageX: pageX value for the mouse event
  • pageY: pageY value for the mouse event
  • screenX: screenX value for the mouse event
  • screenY: screenY value for the mouse event
  • timestamp: timestamp of event; this will be used to calculate the time between one event and the next, so no need for the timestamps to start from zero
  • element: DOM element on which to fire mouse event (this is optional; if the element is not specified, event will be fired on document.body instead)

duration for all mouse movements is expressed in milliseconds, e.g. virtualpointer.move_to_element_and_click(element, 5000) will take 5 seconds to complete the mouse movements

Example

open up example.html and open up the JavaScript console in your web-browser; you should have a log of events that have been fired programmatically.... you can then run any of the commands above

example commands:

virtualpointer.move_mouse_to_element($("#firstHeading"), 2500);

virtualpointer.flick_to_element($("#footer"), 2500);

virtualpointer.move_to_element_and_click( $("#pt-createaccount a"), 1000);

note: this last command will redirect you to the create account page on wikipedia since the command moves the mouse to the create account link and then clicks on it

Dependencies

None; uses native JavaScript

Potential Issues

You can't run this inside a headless browser that depends on the jsdom.js library, such as Zombie.js, because jsdom.js doesn't have any notion of page layout (or dimensions of elements on the page) and does not implement getBoundingClientRect, etc.

You can't run touch events inside browsers that do not support touch events; the fallback is to just use mousedown / mousemove / mouseup for these cases

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.