Reputation: 909
I would like to get my page to read keystrokes wherever the person is focused on the website.
So like if they had the web page open and they pressed 1 then it did something and if they pressed 2 it did something else and so on. I don't mean to do this in an input tag.
How would I go about doing this? Can PHP just catch the keystroke and do something or does it have to respond back with AJAX? If so, how?
Upvotes: 0
Views: 657
Reputation: 44649
You'll need to listen to a keyboard event with JavaScript.
PHP is a server side language and cannot help you for this.
Simple demo over here: http://jsbin.com/lamow/1/edit
document.addEventListener('keypress', function(event) {
console.log(arguments);
});
Upvotes: 1