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.
Questions tagged [onkeypress]
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....');
}
},
…
![](../../users/profiles/544079.webp)
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…
![](../../users/profiles/243999.webp)
Donal Rafferty
- 19,239
- 37
- 110
- 186
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 =…
![](../../users/profiles/12597.webp)
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…
![](../../users/profiles/788679.webp)
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…
![](../../users/profiles/497060.webp)
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. …
![](../../users/profiles/439317.webp)
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…
![](../../users/profiles/185570.webp)
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…
![](../../users/profiles/507153.webp)
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'
![](../../users/profiles/612987.webp)
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
![](../../users/profiles/2195092.webp)
Lucy
- 1,648
- 14
- 46
- 82
11
votes
5 answers
how to Send string from Android to PC over wifi
Hello i am working on an android app which requires to send a string over wifi to PC resulting in simulating keyboard keypresses.Any ideas how i can achieve this task ?
![](../../users/profiles/785034.webp)
Hasham Tahir
- 209
- 1
- 4
- 12
10
votes
3 answers
How to differentiate between long key press and regular key press?
I'm trying to override the functionality of the back key press. When the user presses it once, I want it to come back to the previous screen. However, when the back key is long-pressed (for, let's say, two seconds or more), I want to exit the…
![](../../users/profiles/813951.webp)
Mister Smith
- 24,695
- 17
- 97
- 181
10
votes
3 answers
JavaScript key handling and browser compatibility
I'm working on key handling in Javascript. I have done some research and I'd like to know whether I have a correct understanding of key handling.
KeyDown/KeyUp Event
The key down and key up events are supported by IE7+ and Firefox 3.5+ I didn't…
user338195
10
votes
6 answers
How can I check the new value of a text field on keypress?
I have a single form field and I need to be able to detect when the field changes and execute some additional code using the new value of the field. I only want to execute the code if the key pushed actually changes the value of the text box. Here's…
![](../../users/profiles/163699.webp)
Stephen Sorensen
- 9,969
- 11
- 29
- 42
9
votes
4 answers
onKeyPress event in Firefox and IE8
I have the following Javascript code. Here I am using onKeyPress="someFunction( )" in the body tag to get the keyCode of the key that is pressed.
The code is working fine in IE8 but this is not working in Firefox.
Please give some solution to…
![](../../users/profiles/536146.webp)
Nirmal
- 115
- 1
- 1
- 6