title: Handling events for mouse click and keydown or keypress (for non-modifier keys)
body: <p>I am new to JS and trying to learn on my own - thanks for any help!</p>
  
  <p>I am trying to have a simple program respond to a click differently depending on what other key is pressed at the time of the mouse click.</p>
  
  <p>I have searched far and wide and have not been able to find an answer that works for non-modifier keys alt and shift (which I have had no trouble implementing).  However, I can't for the life of me figure out how to achieve the same result with a regular character key.</p>
  
  <p><a href="http://jsfiddle.net/nick_craver/Du7rQ/" rel="noreferrer">The example below (which I found in other comments on this site)</a> works if the alt key is employed.</p>
  
  <pre><code>&lt;div id="targetDiv"&gt;I want to put a ding in the universe.&lt;/div&gt;
  
  $(function() {
    $("#targetDiv").click(function(event) {
      if (event.altKey) {
         //do something, alt was down when clicked
      }
    });
  });
  </code></pre>
  
  <p>However, the intuitive modification does not work.  </p>
  
  <p>For example, the otherwise identical code (now using event.keyCode===114) does not work <strong>(?!)</strong> when the 'r' key is pressed (nor does event.charCode===114 do the trick):</p>
  
  <pre><code> &lt;div id="targetDiv"&gt;I want to put a ding in the universe.&lt;/div&gt;
      $(function() {
            $("#targetDiv").click(function(event) {
              if (event.keyCode===114) {
                 //do something, alt was down when clicked
              }
            });
          });
  </code></pre>
  
  <p>What went wrong?</p>
  
  <p>I am able to get functionality out of a keyPress if I listen to it alone:</p>
  
  <pre><code>addEventListener("keypress", rIsPressed, false);
  
  function rIsPressed(event){
      if(event.keyCode===114){    
      console.log("the 'r' key is pressed");
      }
  }
  </code></pre>
  
  <p>however nothing seems to work when I try to pair a character keypress with a mouse click or even a character keypress with a modifier keypress:</p>
  
  <pre><code>addEventListener("keypress", rIsPressed, false);
  
  function rIsPressed(event){
      if((event.keyCode===114) &amp;&amp; (event.altKey)){    
      console.log("the 'alt' and 'r' keys are pressed");
      }
  }
  </code></pre>
  
  <p>Note: I have tried keydown instead of keypress in all of these examples with no success.</p>
  
  <p>Suggestions please on what I am missing or overlooking - what is problematic about pairing a character key down/press with a modifier key or a mouse click !?</p>
  
  <p>Thank you!!</p>