I have a function so that when you press a key, for example "and", youtube will open (as an event listener of 'keydown')
I have a input
where I can not write because when I press one of the keys I already have as a shortcut inside the function, I open the page that is assigned to it.
I would like to know if there is a way so that, when the input is in focus, the function is not executed.
var cuadroBusqueda = document.getElementById('buscar').focus(); -> Sí está en focus
var btn = document.addEventListener('keydown', pressKey); ->quiero que se remueva sólo sí el unput de busqueda está en focus
function pressKey(e) {
if(e.keyCode == 89)
window.open("https://www.youtube.com/")
};
Update: Thanks for the answers, I tried to do it with Marcos Martinez's method but unfortunately it did not work, what I mean or I'm looking to do is that having this pressKey () function opens a site by pressing a key for example I'm in the index.html of the page I'm doing, and I press the "and" key then redirects me to the youtube page. I already have it, now I have a search bar but when I have the function, if I am writing my search, pressing "and" opens YouTube and does not allow me to write, what I want to do is that when I'm in focus my search input, by pressing "and" do not open youtube
Update 2: Thank you very much for your help, in fact running the code of your answers works perfectly but doing it in the code that I wrote something is not right, I suppose it would transcribe it well YouTube is not the only key within my function. Once again, infinite thanks for your help. : D !!!