Created
October 21, 2014 19:04
-
-
Save DanBrink91/7c130e71506942335332 to your computer and use it in GitHub Desktop.
Revisions
-
DanBrink91 created this gist
Oct 21, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } return text; } var keysDown = {}; window.addEventListener("keyup", function(e){ keysDown[e.keyCode] = false; }); window.addEventListener("keydown", function(e){ keysDown[e.keyCode] = true; // ctrl + ` if(keysDown[192] && keysDown[17]){ var text = getSelectionText(); // do something with selected text } });