Hacker News new | ask | show | jobs
by Bognar 3673 days ago
This sequence seems to settle right around 50%:

  var simulateKeyPress = function(character) {
    var evt = document.createEvent("KeyboardEvent");
    evt.initKeyEvent ("keypress", true, true, window,
                      0, 0, 0, 0,
                      0, character.charCodeAt(0)) 
    document.body.dispatchEvent(evt);
  };
  
  var num = 0;
  var loop = function() {
    console.log(num);
    var binary = num.toString(2);
    num++;
    for(var i = 0, len = binary.length; i < len; i++) {
      simulateKeyPress(binary[i] == '0' ? 'd' : 'f');
    }
  };
  
  setInterval(loop, 100);
1 comments

It might sound weird, but I actually found that more readable as three lines of code. :/