W
W
war762015-01-06 23:20:19
Google Chrome
war76, 2015-01-06 23:20:19

How to remove alt activity?

Hello everyone
I ran into such a problem: when I enter some text in input or div[contenteditable] I want my function to be called when alt is pressed, the
problem is that in Chrome (possibly in other browsers, not tested) when I click on alt focus is lost from the field (when pressed again, it returns back). Peculiar toggleFocus (joke for 300) The
question is how to make it so that when I press alt, only my function fires and nothing else?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Nalomenko, 2015-01-06
@war76

On Windows, any window interprets pressing the alt key as an action that initiates the opening of the current window's menu. And, as a result, the focus of your input is lost.
To prevent this situation use preventDefault

var element = document.querySelector("#InputID");
element.onkeyup = function(e){
   var key = e.keyCode || e.which;
   if(key===18) {
      e.preventDefault();
   }
};

A
Alexander Taratin, 2015-01-06
@Taraflex

jsfiddle.net/QW01_01/8fexst0h

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question