title: Adding a custom keyboard shortcut using userscript to Chrome with Tampermonkey
body: <p>I would like to add some custom keyboard shortcuts to a certain web page.</p>
  
  <p>Using the accepted answer from this question as a guide: <a href="https://stackoverflow.com/questions/2511388/how-can-i-add-a-javascript-keyboard-shortcut-to-an-existing-javascript-function">How can I add a JavaScript keyboard shortcut to an existing JavaScript Function?</a></p>
  
  <p>I made my own little function and added a listener:</p>
  
  <pre><code>// ==UserScript==
  // @name       ChartGame
  // @namespace  http://www.chartgame.com/
  // @version    0.1
  // @description  enter something useful
  // @match      http://www.chartgame.com/play*
  // @copyright  2012+, You
  // ==/UserScript==
  function doc_keyUp(e) {
    switch(e.keyCode)
    {
    case 49: //1
      mon_clk(3);
      break;
    case 50:
      mon_clk(6);
      break;
    case 83: //s
      BuySell(0);
      break;
    case 68: //d
      BuySell(1);
      break;
    case 70: //f
      TimelapseDwn();
      TimelapseUp();
      break;
     default:
       break;
    }
  }
  document.addEventListener('keyup', doc_keyUp, false);
  </code></pre>
  
  <p>This code runs just perfectly fine if I enter it into the Chrome javascript console while on the appropriate web page. I can use the keyboard shortcuts as I intended. The only problem is that I have to reenter javascript code including the listener if I go to a next game(that is chart..).</p>
  
  <p>My impression was that Tampermonkey would allow me to run this script automatically on specific pages that match the expression on <code>@match</code>. The code does appear to run, but there is no keyboard shortcut functionality.</p>
  
  <p>What is missing or what is different from running javascript code from Chrome console and from an extension such as Tampermonkey? </p>