0

I am trying to do a hidden hotkey on my website. i want to make it so that if you type ctrl + dev, and alert will pop up.

here is what i have so far.

$(document).keypress(function(e) {
  if(e.ctrlKey) {
    if (e.which == 4 && e.which == 5 && e.which == 22) {
      alert("it worked");
    }
  }
});

it works if i just have one check with out the && but not with all those. I know that might be wrong, but how do i make it work 4 = d, 5 = e, 22 = v in case you didn't know.

Any help would be greatly appreciated.

Doctor06
  • 677
  • 1
  • 13
  • 28
  • 2
    `||` ([Logical OR](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_Operators#Logical_OR)). `e.which` can't both be 4 `&&` 5 at the same time. – Jonathan Lonowski May 22 '14 at 19:58
  • `&&` means "AND", while `||` means "OR" in javascript. – Sean Kendle May 22 '14 at 20:00
  • you want to use `keydown` not `keypress`, as `keypress` won't return multiple "normal" keys (just a normal key + modifier like shift, ctrl etc). so it will only return d, e or v not all 3 – Ennui May 22 '14 at 20:00
  • see this answer: http://stackoverflow.com/questions/4954403/can-jquery-keypress-detect-more-than-one-key-at-the-same-time – Ennui May 22 '14 at 20:01

0 Answers0