Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect key down event for arrow key on textarea?

Create the following html-page:

<textarea id="code" rows="10"></textarea>
<script>
  document.onkeydown = function(event) {
    alert(event.keyCode);
  }
</script>

Open it on Mobile Safari (on a simulator or on a device with keyboard), tap on textarea to start editing. And now press any arrow key - event won't fire.

How to detect key down for arrow keys?

P.S. Related issue on Apple Bug Report system: 13243285

like image 820
Dmitry Avatar asked Feb 19 '13 13:02

Dmitry


People also ask

What is e keyCode === 13?

Keycode 13 is the Enter key.

How do you call an arrow key in JavaScript?

To detect the arrow key when it is pressed, use onkeydown in JavaScript. The button has key code. As you know the left arrow key has the code 37. The up arrow key has the code 38 and right has the 39 and down has 40.

What's the difference between event key and event code key event properties?

code and event. key. The key property of the event object allows to get the character, while the code property of the event object allows to get the “physical key code”. For instance, the same key Z can be pressed with or without Shift .


2 Answers

Official answer from Apple:

Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.

like image 86
Dmitry Avatar answered Oct 05 '22 07:10

Dmitry


$(selector).keydown(function(e){
    if (e.keyCode == 37) { 
       alert( "left pressed" );
       return false;
    }
});

Character codes:

37 - left

38 - up

39 - right

40 - down

like image 30
sasi Avatar answered Oct 05 '22 05:10

sasi