Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Record and store mouse movements

My requirements are that every time a user enters the page the mouse movements start to get recorded and once the user leaves the page, all the data (Coords x, y and time) gets sent to a server for later analysis.

like image 357
Wolfgang Avatar asked Aug 12 '14 09:08

Wolfgang


People also ask

Can you record mouse movements?

If your mouse has a Macro Record button, you can record macros while you are running a program or playing a game. You can edit these macros later using the Macro Editor in the Microsoft Mouse and Keyboard Center. Note: You cannot capture mouse movement or actions performed through macros reassigned to a button/key.

How do I record mouse movement and repeat it?

Mouse actions can be recorded and played back using hotkeys, which are set to F9 and F11 for playback and record mode respectively. The same recorded action can be repeated several times regularly based on a time interval and an execution delay can also be set.

Can you make a macro for mouse movement?

You can record events such as keystrokes, mouse clicks, and delays between actions. You cannot capture mouse movement or actions performed through macros assigned to reassignable keys.


1 Answers

unload()

Javascript:

document.onmousemove = function(e){
  var pageCoords = "( " + e.pageX + ", " + e.pageY + " )";
  console.log(pageCoords);
};

DEMO

Unload javascript:

window.onunload=function(){
  //SomeJavaScriptCode
};

jQuery:

var pageCoords = []; //array for storing coordinates
$(document).onmousemove = function(e){
  pageCoords.push("( " + e.pageX + ", " + e.pageY + " )");//get page coordinates and storing in array
}
$( window ).unload(function() {
  //make ajax call to save coordinates array to database
});

UPDATED DEMO

like image 122
Manwal Avatar answered Sep 21 '22 17:09

Manwal