title: Using javascript to create a keylistener hotkey for facebook page "like"
body: <p><em>I'm doing an art project for school where a user hugs an object and gets a "liked" status on Facebook.  Everything pretty much works; however, I need to set up a keyboard listener in a userscript.</em> </p>
  
  <p><strong>the Problem:</strong><br>
   How do I make a hotkey execute the unsafeWindow.Otomatislike function?  If so could anyone show me how to combine these codes.  I'm pretty certain my symantics are what make it fail.</p>
  
  <p>100% working <strong>like status code</strong></p>
  
  <pre><code>   body = document.body;
  if(body != null) {
      div = document.createElement("div");
      div.setAttribute('id','like2');
      div.style.position = "fixed";
      div.style.display = "block";
      div.style.width = "125px"; 
      div.style.opacity= 0.90;
      div.style.bottom = "+42px";
      div.style.left = "+6px";
      div.style.backgroundColor = "#eceff5";
      div.style.border = "1px solid #94a3c4";
      div.style.padding = "2px";
      div.innerHTML = "&lt;img src='http://g1203.hizliresim.com/v/n/3pnck.png' width='16' height='14' align='absmiddle' /&gt;&amp;nbsp;&amp;nbsp;&lt;a onclick='OtomatisLike()'&gt;Like&lt;/a&gt;"
  
      body.appendChild(div);
  
      unsafeWindow.OtomatisLike = function() {
  
          input = document.getElementsByTagName("input");
          for(i = 0; i &lt; input.length; i++) {
              myID = input[i].getAttribute("data-profileid");
              if(myID != null &amp;&amp; myID.indexOf("14226545351") &gt;= 0)
                  input[i].click();
          }
  
      };
  }
  </code></pre>
  
  <p>this code creates a small button in the bottom left corner to like the redbull page when on it. ie. <a href="http://vvcap.net/db/CTHpxz8qeuuZX1yy5tEd.htp" rel="nofollow">http://vvcap.net/db/CTHpxz8qeuuZX1yy5tEd.htp</a></p>
  
  <p><strong>problem</strong>  I would like to add a keyboard listener to this instead of the secondary div "button" I've styled.  <a href="http://vvcap.net/db/M0XbpT5Sw8BmOtfAHJ4m.htp" rel="nofollow">http://vvcap.net/db/M0XbpT5Sw8BmOtfAHJ4m.htp</a></p>
  
  <p>I've found some sample code that look revelvent; however, I'm having a lot of troble figuring out how to implement it:<a href="http://www.catswhocode.com/blog/using-keyboard-shortcuts-in-javascript" rel="nofollow">hotkey citation</a></p>
  
  <pre><code>    var isCtrl = false;
  document.onkeyup=function(e) {
      if(e.which == 17) isCtrl=false;
  }document.onkeydown=function(e){
      if(e.which == 17) isCtrl=true;
      if(e.which == 96 &amp;&amp; isCtrl == true) {
           alert('Keyboard shortcuts are cool!');
           return false;
      }
  }
  </code></pre>
  
  <p>While this code makes logical sense I'm totally unable to implement it. 17 = ctnl key while 96 == numpad 0.  therefore the hotkey == ctnl + 0 (numpad).  of course the alert would be replaced with the facebook like function</p>
  
  <p><strong>FINAL CODE ANSWERED</strong></p>
  
  <pre><code>    // ==UserScript==
  // @name            Facebook Like By Virgan
  // @namespace               http://userscripts.org/scripts/show/123303
  // @version         0.3
  // @copyright               Virgan
  // @description             Auto Like And Confirm (mass) | You can mass like and confirm
  // @author          Virgan (http://userscripts.org/users/430638)
  // @icon            https://lh4.googleusercontent.com/-2A1Jpr4-1qM/TxPUbMq8IQI/AAAAAAAAAIU/_50N6LEgkxE/h120/FB.png
  // @require         http://code.jquery.com/jquery.min.js
  // @include         http://www.facebook.com/*
  // @include         https://www.facebook.com/*
  // @exclude         htt*://developers.facebook.com/*
  //
  // Copyright (c) 2012, Virgan
  // Auto Like/Unlike, And Another Function.
  
  
  // ==/UserScript==
  
  // ==Profile==
  unsafeWindow.OtomatisLike = OtomatisLike;
  function OtomatisLike() 
      {   
          input = document.getElementsByTagName("input");
          for(i = 0; i &lt; input.length; i++) 
              {
                  myID = input[i].getAttribute("data-profileid");
                  if(myID != null &amp;&amp; myID.indexOf("14226545351") &gt;= 0)
                  input[i].click();
              }
  
      }
  
  
  $(window).load(function(){
  
      var isCtrl = false;
      document.onkeyup=function(e) {
          if(e.which == 17) isCtrl=false;
      }
      document.onkeydown=function(e){
          if(e.which == 17) isCtrl=true;
          if(e.which == 96 &amp;&amp; isCtrl == true) {
              OtomatisLike()
  
              return false;
          }
      }
  
  });
  </code></pre>
  
  <p>Thank you for all your help
  if you want to know more about the project <a href="http://designobvio.us/CLASSES/like+pillowv3.pdf" rel="nofollow">pdf presetnation</a></p>