Skip to content

Instantly share code, notes, and snippets.

@konstantinos-tsatsarounos
Created June 25, 2016 00:34
Show Gist options
  • Select an option

  • Save konstantinos-tsatsarounos/59f7959672f9386d227c206e2b10f1ce to your computer and use it in GitHub Desktop.

Select an option

Save konstantinos-tsatsarounos/59f7959672f9386d227c206e2b10f1ce to your computer and use it in GitHub Desktop.
function pressSpace(target, type) {
var press = new KeyboardEvent(type, {"keyCode": 32});
if(type == 'keyup'){ target.value += ' ';}
target.dispatchEvent(press);
}
function type(){
var text = document.getElementById('words');
var currentword = document.getElementById('currentword');
var input = document.getElementById('input');
if(input.value.indexOf('currentword.innerText') == -1){
input.value = currentword.innerText;
pressSpace(input, 'keydown');
setTimeout( function(){
pressSpace(input, 'keyup');
}, 200);
}
}
// document.getElementById('input').addEventListener('keyup', function(evt){ console.log(evt.keyCode); } );
var handler = setInterval(type, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment