title: Binding Javascript keypress events
body: <p>I have a need to monitor the state of the <kbd>Shift</kbd> key, whether it is up or down. Its purpose is to notify the user that while the <kbd>shift</kbd> key is held down, the drag and drop operation they are about to perform is going to COPY the node(s), and not move them.</p>
  <p>I have it working perfectly with the code below, however, if I hold the <kbd>Shift</kbd> key and perform the drag and drop, the hook no longer exists; the screen no longer responds to the key press and remains in the &quot;pressed&quot; state.</p>
  <p>I'm guessing there is either an order of operations issue or a missing piece. Javascript experts please advise.</p>
  <pre><code>&lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
  &lt;div&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td valign=&quot;top&quot;&gt;&lt;ASP:Literal id=&quot;treeLeft&quot; EnableViewState=&quot;false&quot; runat=&quot;server&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      
      &lt;asp:Label ID=&quot;lblCopyEnabled&quot; runat=&quot;server&quot; BackColor=&quot;Green&quot; Text=&quot;Item will be Copied&quot; ForeColor=&quot;White&quot; Font-Bold=&quot;true&quot; style=&quot;padding: 0px 10px 0px 10px; display: none&quot; /&gt;
  &lt;/div&gt;
  
   &lt;script type=&quot;text/javascript&quot;&gt;
       document.onkeydown = KeyDownHandler;
       document.onkeyup = KeyUpHandler;
  
       var SHIFT = false;
  
       function KeyDownHandler(e) {
           var x = '';
           if (document.all) {
               var evnt = window.event;
               x = evnt.keyCode;
           }
           else {
               x = e.keyCode;
           }
           DetectKeys(x, true);
           ShowReport();
       }
       function KeyUpHandler(e) {
           var x = '';
           if (document.all) {
               var evnt = window.event;
               x = evnt.keyCode;
           }
           else {
               x = e.keyCode;
           }
           DetectKeys(x, false);
           ShowReport();
       }
       function DetectKeys(KeyCode, IsKeyDown) {
           if (KeyCode == '16') {
               SHIFT = IsKeyDown;
           }
           else {
               if (IsKeyDown)
                   CHAR_CODE = KeyCode;
               else
                   CHAR_CODE = -1;
           }
       }
       function ShowReport() {
           var copyLabel = document.getElementById(&quot;&lt;%= lblCopyEnabled.ClientID %&gt;&quot;);
           if (SHIFT) {
               copyLabel.style.display = &quot;inline&quot;;
               ob_copyOnNodeDrop = true;
           }
           else {
               copyLabel.style.display = &quot;none&quot;;
               ob_copyOnNodeDrop = false;
           }
           
       }
  &lt;/script&gt;
  
  &lt;/form&gt;
  </code></pre>