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
163
votes
7 answers

How can I listen for keypress event on the whole page?

I'm looking for a way to bind a function to my whole page (when a user presses a key, I want it to trigger a function in my component.ts) It was easy in AngularJS with a ng-keypress but it does not work with (keypress)="handleInput($event)". I…
L.querter
  • 2,332
  • 2
  • 13
  • 23
156
votes
10 answers

How to find out what character key is pressed?

I would like to find out what character key is pressed in a cross-browser compatible way in pure Javascript.
xXx
  • 1,631
  • 2
  • 12
  • 5
131
votes
5 answers

Capturing "Delete" Keypress with jQuery

When using the example code from the jQuery documentation for the keypress event handler, I'm unable to capture the Delete key. The snippet below is going to log 0 when the Delete key is pressed in FireFox: $(document).keypress(function(e) { …
Shane H
  • 3,263
  • 5
  • 26
  • 30
101
votes
6 answers

Angular 2 HostListener keypress detect escape key?

I am using the following method to detect keypresses on a page. My plan is to detect when the Escape key is pressed and run a method if so. For the moment I am just attempting to log which key is pressed. However the Escape key is never detected.…
Jeremy P
  • 1,309
  • 2
  • 13
  • 22
91
votes
13 answers

How to trigger an event in input text after I stop typing/writing?

I want to trigger an event just after I stop typing (not while typing) characters in my input textbox. I've tried with: $('input#username').keypress(function() { var _this = $(this); // copy of this object for further usage …
user1386320
83
votes
6 answers

jQuery Keypress Arrow Keys

I'm attempting to capture arrow key presses in jQuery, but no events are being triggered. $(function(){ $('html').keypress(function(e){ console.log(e); }); }); This generates events for alphanumeric keys, but delete, arrow keys, etc…
RedBassett
  • 3,469
  • 3
  • 32
  • 56
73
votes
5 answers

How to make a submit button in WPF?

When you press Enter anywhere in a HTML form it triggers its action, that is equivalent of pressing the submit button. How to make a window that when I press Enter anywhere it will trigger an event?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
69
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
  • 2,025
  • 8
  • 43
  • 62
67
votes
6 answers

jQuery's 'keypress' doesn't work for some keys in Chrome. How to work around?

I'm trying to implement key-press functionality which will remove a div when the user hits Esc. This works for Firefox & IE with the following code: $("body").keypress(function(e) { alert("any key pressed"); if (e.keyCode == 27) { …
DaveDev
  • 41,155
  • 72
  • 223
  • 385
57
votes
3 answers

Detecting enter on a QLineEdit or QPushButton

I've built an app for a game, simple to start. It's a game in which the system randomly chooses a number and a gamer (player) tries to find out the number. Everything is almost done. The app consists of a QLineEdit, a label and three buttons. Once…
arkero24
  • 669
  • 1
  • 5
  • 7
54
votes
11 answers

keypress, ctrl+c (or some combo like that)

I'm trying to create shortcuts on the website I'm making. I know I can do it this way: if(e.which == 17) isCtrl=true; if(e.which == 83 && isCtrl == true) { alert('CTRL+S COMBO WAS PRESSED!') //run code for CTRL+S -- ie, save! …
android.nick
  • 11,069
  • 23
  • 77
  • 112
51
votes
7 answers

Make a specific column only accept numeric value in datagridview in Keypress event

I need to make datagridview that only accept the numeric value for specific column only in keypress event. Is there any best way to do this?
Eplzong
  • 670
  • 1
  • 8
  • 13
50
votes
4 answers

jQuery: trigger keypress function on entire document but not inside inputs and textareas?

I have this … $(document).keypress(function(e) { if ( e.keyCode === 119 ) // w doSomething(); }); Wo when pressing "w" on my document the doSomething() function fires. How can I prevent it from firing when I'm currently…
matt
  • 42,713
  • 103
  • 264
  • 397
49
votes
3 answers

What's the theory behind jQuery keypress, keydown, keyup black magic (on Macs)?

I am confused about the various behaviors of keypress, keydown, and keyup. It seems that I have missed an important piece of documentation, one that explains the subtleties and nuances of this trio. Could someone help me to figure out which document…
SaganRitual
  • 3,143
  • 2
  • 24
  • 40
49
votes
15 answers

Pressing Ctrl + A in Selenium WebDriver

Is there a way to press the Ctrl + A keys using Selenium WebDriver? I checked the Selenium libraries and found that Selenium allows key press of special and function keys only.
AJJ
  • 3,570
  • 7
  • 43
  • 76