JSFiddle - React, Tailwind, and code Playground
HTML
<div id="cmd">
<textarea id="cmdText" maxlength="80"></textarea>
</div>
JavaScript
function execCMD(command) {
if(command.trim() == "exit")
$("#cmd").hide("fast");
console.log(command);
}
function showCMD() {
$("#cmd").show("fast");
$('#cmdText').focus();
}
document.onkeyup = function(event) {
//Save the last three keys
three = event.keyCode;
two = three;
one = two;
if (one == 67 && two == 77 && three == 68 && cmdOpen == false) {
showCMD();
}
//if the pressed key is ENTER and the textarea is focused
if (event.keyCode == 13 && $("#cmdText").is(":focus") == true) {
//passing the code to another function
execCMD(document.getElementById("cmdText").value);
//empty the textarea - works great
document.getElementById("cmdText").value = "";
return false;
}
}