I am creating a browser game and i have keys set which moves the player around. Let's get a weird example to help understand the problem.
Space bar - Jump
So when i go to the chatbox, and start typing the player jumps every time you press the space bar like it is intended to. However, when i am typing in a input field, it should not jump the player for pressing the space bar.
This is the input field:
<textarea id="chatfield1" class="pull-left" placeholder="Participate in coversation"></textarea>
I have a keymanager that enables and disables the ability to execute functions with keys.
keymanager.suspend();
keymanager.resume();
How could i do this?
edit: My keymanager works like this:
var keymanager = {
"active": true,
"suspend": () => {
keymanager.active = false;
},
"resume": () => {
keymanager.active = true;
}
};
document.body.onkeyup = function(e){
if (!keymanager.active)
{
return; // do not process any keys
}