jdsninja
jdsninja

Reputation: 1

How to store mouse & keyboard event and value

I want to record everything a user do in a web page (click, double click, key press, scroll, ect). I also want to record when does the event happen.

What will be the best way for storing all those info. Json, arrays, object or string?

So far, I'm storing everything in a string like that: c|15:33:22-dc|15:32:14 c = click dc = double click

I need to make sure the information is easy to extract.

Upvotes: 0

Views: 1512

Answers (2)

John Hartsock
John Hartsock

Reputation: 86882

Every event in the Document Object Model is wrapped in an event object. https://developer.mozilla.org/en-US/docs/Web/API/Event/Event

If I create an onclick event one of the parameters for that function is the event. You can record these event objects.

jQuery

var myEventList= [],
$('#myID').on('click', function(event) {
   myEventList.push(event);
});

JavaScript

var myEventList=[];
document.getElementById('myID').onclick = function(event) {
   myEventList.push(event)
};

Upvotes: 1

Alexander
Alexander

Reputation: 64

Where do you want to store this data?

For work/collect this events I would suggest you using the object with array inside. Like this:

var eventsLog = {"mouse":[],"keyboard":[]};

When event fired, you just push it into array. It's comfortable.

var insert = [new Date(), 'event_name'];
(eventsLog.mouse).push(insert);

And when you want to transfer data to another app, you will simply convert the data into the required format.

Upvotes: 0

Related Questions