Forum Moderators: open

Message Too Old, No Replies

Not sure how to capture type without a form

php

         

jonorr

6:43 am on May 2, 2013 (gmt 0)

10+ Year Member



I would like to embed an easter egg in my page where it activated by someone typing in "up, up, down, down, left, right, left, right, B, A, enter" while they are on the page. I do not want a form on the page. is this even possible in php?

Many thanks

Jono

topr8

7:09 am on May 2, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



php is a server side technology, it cannot capture anything the user does.
i'm not a javascript guru but i imagine that is what you want to do what you desire.

jonorr

8:04 pm on May 2, 2013 (gmt 0)

10+ Year Member



awesome I will look into that.

Thanks

Readie

9:11 pm on May 7, 2013 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As topr8 said, not the right forum, but...

Using the jQuery plugin ([jquery.com ]), this will do what you want to do. Just replace that alert with your easter egg code:

(function($) {
var sequence = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65, 13];
var currentSequence = [];
$(document).ready(function() {
$(window).on('keydown', function(event) {
if(sequence[currentSequence.length] != event.which) {
currentSequence = [];
return;
}
currentSequence.push(event.which);
if(sequence.length == currentSequence.length) {
currentSequence = [];
alert('THA KONAMI CODE!');
}
});
});
})(jQuery);

I suggest using the jQuery plugin (Or a similar tool) for this sort of thing, as the keyboard "key codes" can vary between browsers, and jQuery normalizes them for you through .which