I am using a function to show a div:
function showCMD() {
$("#cmd").show("fast");
$('#cmdText').focus();
}
This happens, if the user is typing "cmd" on his keyboard.
Main code:
document.onkeyup = function(event) {
//Save the last three keys
one = two;
two = three;
three = event.keyCode;
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;
}
}
The code typed in by the user will be handled here:
function execCMD(command) {
if(command == "exit") $("#cmd").hide("fast");
console.log(command);
}
console gives me every time exit. But it doesn't hide the div #cmd. If I change onkeyup to onkeydown, it works fine. The problem with onkeydown is, that the textarea shows the "d", after opening the command line with key sequence "cmd".
So either I can't close the #cmd or it shows a "d" every time I open the #cmd.
Last but not least the html code:
<div id="cmd">
<textarea id="cmdText" maxlength="80"></textarea>
</div>
Maybe you will know a solution for my problem! Thank you so far