Questions tagged [onkeypress]

Unlike other key events in javascript, keypress may capture the actual character, that would be inserted in text field (only applies on editable elements, like text fields and content-editable html elements). This is hidint under event.charCode. On other events, such as keyup and keydown you only may capture ID of the key - with different systems, and languages, the same number may mean totally different characters.
On the other side, keypress along with keyup may not block many default event actions - like pressing tab, F5 or arrows.

355 questions
256
votes
11 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
  • 13,851
  • 35
  • 102
  • 160
210
votes
10 answers

Android - How To Override the "Back" button so it doesn't Finish() my Activity?

I currently have an Activity that when it gets displayed a Notification will also get displayed in the Notification bar. This is so that when the User presses home and the Activity gets pushed to the background they can get back to the Activity via…
89
votes
12 answers

How to get text of an input text box during onKeyPress?

I am trying to get the text in a text box as the user types in it (jsfiddle playground): function edValueKeyPress() { var edValue = document.getElementById("edValue"); var s = edValue.value; var lblValue =…
Ian Boyd
  • 220,884
  • 228
  • 805
  • 1,125
56
votes
11 answers

How to capture Enter key press?

In my HTML page, I had a textbox for user to input keyword for searching. When they click the search button, the JavaScript function will generate a URL and run in new window. The JavaScript function work properly when the user clicks the search…
Joe Yan
  • 1,785
  • 7
  • 40
  • 61
41
votes
5 answers

jQuery keypress left/right navigation

I want to give my content slider the ability to respond to keypress (LEFT ARROW key and RIGHT ARROW key) feature. I have read about some conflicts between several browsers and operation systems. The user can navigate the content while he is on the…
Tomkay
  • 4,801
  • 20
  • 55
  • 91
32
votes
6 answers

keyPressEvent.getCharCode() returning 0 for all special keys like enter, tab, escape, etc

My code: @Override public void onKeyPress(KeyPressEvent event) { if (event.getCharCode() == KeyCodes.KEY_ENTER) { registerButton.click(); } } This is attached to a TextBox, and it does fire when I press enter. …
Riley Lark
  • 19,952
  • 14
  • 75
  • 122
28
votes
3 answers

How do I disable Firefox's "Search for text when I start typing" on pages with keyboard shortcuts?

Some web pages such as GMail and Reddit(with the Reddit Enhancement Suite) have useful keyboard shortcuts that I'd like to use. However, whenever I start typing on one of these pages, the first onkeypress event fires, but then the "Search for text…
BinarySplit
  • 488
  • 4
  • 8
23
votes
6 answers

onKeyListener not working on virtual keyboard

I don't understand why this piece of code is not working. Only backspace and return key are detected. Listener doesn't fire for any other key. My device is Nexus One. I tried to override activity's OnKeyDown method and that's even worse. The only…
bobetko
  • 4,666
  • 13
  • 56
  • 81
14
votes
3 answers

Javascript Last character missing on OnKeyPress event

function h(x) { alert(x); } when i press 'a' alert empty when i press 'b' after 'a' =>ab alert only 'a' and i want 'ab' when i type 'abcd' it alert 'abc' only and i want 'abcd'
Wasim A.
  • 8,661
  • 19
  • 86
  • 113
11
votes
5 answers

Javascript Function to enter only alphabets on keypress

I want to enter only character values inside a