This question already has an answer here:
let me clear something up real fast- I'm not making a keylogger. I'm creating a site for a video game where users gain items for doing specific actions in game (such as typing something in chat, etc.).
Because of the way this game works, I feel the best way to do it would be to have a website that would, while open, record everything typed (and negate backspaces) to see if the player had completed the action. Then it would lead them onto the next action.
Is there a way to have a PHP or JavaScript script running inside of the website that would record all keystrokes that are typed while the page is open? Then I can have it just listen until it reads the player execute the command (such as joining a guild or trading somebody)?
-Vivian
</div>
Yes, its very easy to accomplish something like that with jQuery. Once you have included the lib, you can put certain events on elements. A way to set a key listener event, when the user releases the key would be something like this:
$('body').keypress(function (event) {
var character = String.fromCharCode(event.charCode)
alert(character);
});
You can then send the result to php via AJAX (which you can also do pretty easy in jQuery (put this in a separate function and call the function in your keypress function):
var url = 'your_script.php?character=' + character;
$.get(url, function (data) {
alert(data); // alert response from your_script.php
});
You can find the key pressed with javascript. If they're in an input field you could have a function that checks the value of the field on key press also.
This post here answers it.