Jquery: how to disable the function with the keyCode when printing input?

There is jquery code:
function checkKey(e) {

 e = e || window.event;

 if (e.keyCode == '37') {
 else if (e.keyCode == '39') {
 else if (e.keyCode == '80') {
 else if (e.keyCode == '84') {


This feature allows the user to quickly navigate to another page of the website, for example: I press on the keyboard "t" key and I opened the page c tags (tags). But there is a problem: if you enter, for example, in the search (input) this function also works, i.e. if I again click on the "t" key when you type the word "portfolio", I was again transferred to the page with tags. I hope you understand my situation and problem.
I thought when you click on the input add the class "active". And then to make the type of to check with hasClass. But it didn't work.
In jQuery I'm not very strong, so I really hope for your help.

<form class="form-inline my-2 my-lg-0" action="{% url 'posts_list_url' %}">
<input class="form-control mr-sm-2" type="search" placeholder="Search the blog" aria-label="Search" name="search">
 <button class="btn btn-outline-info my-2 my-sm-0 submit-btn" type="submit">Search</button>
March 23rd 20 at 19:46
2 answers
March 23rd 20 at 19:48
You can create a flag, for example typing = false. Inside the keyCode processing all the branches, which, incidentally, can be replaced by switch-case, all branches are wrapped in condition !typing, then hung on all the text input's s the handler function of the event input, which will replace the typing flag to true. I would have done.
March 23rd 20 at 19:50
Do if block: If input items are not active (focus), it actually works in your event handler, or simply prognosis

Find more questions by tags HTMLjQueryJavaScriptCSS