Questions tagged [keypress]

Occurs when a key is pressed while the control has focus.

Occurs when a key is pressed while the control has focus.

This is the key press template primarily designed to illustrate keys and keystrokes on a computer keyboard.

With additional parameters, a single template can even illustrate a combination of multiple simultaneous keystrokes. A sequence of keystrokes, on the other hand, need to be demonstrated with separate templates.

2619 questions
737
votes
24 answers

jQuery Event Keypress: Which key was pressed?

With jQuery, how do I find out which key was pressed when I bind to the keypress event? $('#searchbox input').bind('keypress', function(e) {}); I want to trigger a submit when ENTER is pressed. [Update] Even though I found the (or better: one)…
BlaM
  • 28,465
  • 32
  • 91
  • 105
604
votes
22 answers

Detecting arrow key presses in JavaScript

How do I detect when one of the arrow keys are pressed? I used this to find out: function checkKey(e) { var event = window.event ? window.event : e; console.log(event.keyCode) } Though it worked for every other key, it didn't for arrow keys…
mihsathe
  • 8,904
  • 12
  • 38
  • 54
452
votes
15 answers

How to detect a textbox's content has changed

I want to detect whenever a textbox's content has changed. I can use the keyup method, but that will also detect keystrokes which do not generate letters, like the arrow keys. I thought of two methods of doing this using the keyup event: Check…
olamundo
  • 23,991
  • 34
  • 108
  • 149
380
votes
20 answers

Prevent form submission on Enter key press

I have a form with two text boxes, one select drop down and one radio button. When the enter key is pressed, I want to call my JavaScript function, but when I press it, the form is submitted. How do I prevent the form from being submitted when the…
Shyju
  • 214,206
  • 104
  • 411
  • 497
369
votes
13 answers

Submit form on pressing Enter with AngularJS

In this particular case, what options do I have to make these inputs call a function when I press Enter? Html:
/>
ali
  • 10,927
  • 20
  • 89
  • 138
338
votes
30 answers

Typing the Enter/Return key in Selenium

I'm looking for a quick way to type the Enter or Return key in Selenium. Unfortunately, the form I'm trying to test (not my own code, so I can't modify) doesn't have a Submit button. When working with it manually, I just type Enter or Return. How…
croixhaug
  • 3,767
  • 3
  • 19
  • 12
332
votes
12 answers

How to handle the `onKeyPress` event in ReactJS?

How can I make the onKeyPress event work in ReactJS? It should alert when enter (keyCode=13) is pressed. var Test = React.createClass({ add: function(event){ if(event.keyCode == 13){ alert('Adding....'); } }, …
user544079
  • 16,109
  • 42
  • 115
  • 171
281
votes
10 answers

Definitive way to trigger keypress events with jQuery

I've read all the answers on to this questions and none of the solutions seem to work. Also, I am getting the vibe that triggering keypress with special characters does not work at all. Can someone verify who has done this?
mkoryak
  • 57,086
  • 61
  • 201
  • 257
269
votes
5 answers

JQuery: detect change in input field

I want to detect when a user's keyboard actions alter the value of a text field. It should work consistently across modern browsers. The JQuery page for the .keypress event says it's not consistent? Also, it doesn't work for backspace, delete etc. I…
Jodes
  • 14,118
  • 26
  • 97
  • 156
210
votes
4 answers

jQuery: keyPress Backspace won't fire?

I wonder what I'm doing wrong: $(".s").keypress(function(e) { switch (e.keyCode) { case 8: // Backspace //console.log('backspace'); case 9: // Tab case 13: // Enter case 37: // Left case 38: // Up case…
matt
  • 42,713
  • 103
  • 264
  • 397
194
votes
17 answers

How to detect key presses?

I am making a stopwatch type program in Python and I would like to know how to detect if a key is pressed (such as p for pause and s for stop), and I would not like it to be something like raw_input, which waits for the user's input before…
lobuo
  • 2,167
  • 3
  • 14
  • 8
182
votes
3 answers

How do I capture a key press (or keydown) event on a div element?

How do you trap the keypress or key down event on a DIV element (using jQuery)? What is required to give the DIV element focus?
Lalchand
  • 7,627
  • 26
  • 67
  • 79
177
votes
7 answers

How to wait for a keypress in R?

I want to pause my R script until the user presses a key. How do I do this?
Contango
  • 76,540
  • 58
  • 260
  • 305
171
votes
8 answers

JavaScript listener, "keypress" doesn't detect backspace?

I'm using a keypress listener eg.. addEventListener("keypress", function(event){ } However, this doesn't seem to detect a backspace which erases text... Is there a different listener I can use to detect this?
Skizit
  • 43,506
  • 91
  • 209
  • 269
170
votes
7 answers

onKeyDown event not working on divs in React

I want to use a keyDown event on a div in React. I do: componentWillMount() { document.addEventListener("keydown", this.onKeyPressed.bind(this)); } componentWillUnmount() { document.removeEventListener("keydown",…
Michael
  • 6,823
  • 11
  • 54
  • 84
1
2 3
99 100