Welcome to WebmasterWorld Guest from 107.20.75.63

Forum Moderators: open

Message Too Old, No Replies

Not sure how to capture type without a form

php

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

New User

joined:May 2, 2013
posts: 2
votes: 0


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
7:09 am on May 2, 2013 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2002
posts:3171
votes: 8


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.
8:04 pm on May 2, 2013 (gmt 0)

New User

joined:May 2, 2013
posts: 2
votes: 0


awesome I will look into that.

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:Dec 13, 2009
posts:943
votes: 0


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