Questions tagged [keyboard-events]

An event that is triggered when a Key is pressed on a keyboard input device

A KeyboardEvent is an event that is triggered when a Key is pressed on a keyboard input device. The event will contain information relating to the particular key that was pressed, how long the key was pressed for, and whether any modifier keys were also pressed (such as Ctrl or Alt).

2201 questions
826
votes
19 answers

How can I detect pressing Enter on the keyboard using jQuery?

I would like to detect whether the user has pressed Enter using jQuery. How is this possible? Does it require a plugin? It looks like I need to use the keypress() method. Are there browser issues with that command - like are there any browser…
chris
  • 20,791
  • 29
  • 77
  • 90
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
148
votes
13 answers

Android Use Done button on Keyboard to click button

Ok in my app I have a field for the user to input a number. I have the field set to only accept numbers. When the user clicks on the field it brings up the keyboard. On the keyboard (on ICS) there is a done button. I would like for the done button…
mpeerman
  • 2,050
  • 2
  • 16
  • 16
122
votes
12 answers

How to generate keyboard events?

short summary: I am trying to create a program that will send keyboard events to the computer that for all purposes the simulated events should be treated as actual keystrokes on the keyboard. original post: I am looking for a way to generate…
Inbar Rose
  • 41,843
  • 24
  • 85
  • 131
121
votes
5 answers

How can I programmatically generate keypress events in C#?

How can I programmatically create an event that would simulate a key being pressed on the keyboard?
Dan Vogel
  • 3,858
  • 7
  • 41
  • 57
90
votes
15 answers

Handling key-press events (F1-F12) using JavaScript and jQuery, cross-browser

I want to handle F1-F12 keys using JavaScript and jQuery. I am not sure what pitfalls there are to avoid, and I am not currently able to test implementations in any other browsers than Internet Explorer 8, Google Chrome and Mozilla FireFox 3. Any…
cllpse
  • 21,396
  • 37
  • 131
  • 170
87
votes
5 answers

Firing a Keyboard Event in Safari, using JavaScript

I'm trying to simulate a keyboard event in Safari using JavaScript. I have tried this: var event = document.createEvent("KeyboardEvent"); event.initKeyboardEvent("keypress", true, true, null, false, false, false, false, 115, 0); ...and also…
Steve Harrison
  • 121,227
  • 16
  • 87
  • 72
55
votes
16 answers

How to detect if the pressed key will produce a character inside an text-box?

I have a regular text-box: I use jQuery to handle key-related events: $("input:text").keydown(function() { // keydown code }).keypress(function() { // keypress code }).keyup(function() { // keyup code }); The…
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385
52
votes
3 answers

Capture Control-C in Python

I want to know if it's possible to catch a Control-C in python in the following manner: if input != contr-c: #DO THINGS else: #quit I've read up on stuff with try and except KeyboardInterrupt but they're not working for me.
pauliwago
  • 6,373
  • 11
  • 42
  • 52
52
votes
1 answer

How to simulate typing in input field using jQuery?

What I want is to simulate typing in field using javascript. I have the following code: var press = jQuery.Event("keydown"); press.ctrlKey = false; press.which = 65; $("#test").trigger(press); But when I load the page, the #test input field…
51
votes
3 answers

Hitting Tab in Visual Studio selects block instead of adding indentation

I am using Visual Studio 2015 and ReSharper 2016.2 and I have this strange behavior, that I probably activated (accidentally). When having the cursor in a line before the first word, hitting the Tab-key indents the line correctly: When the cursor…
Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
46
votes
7 answers

Android EditText, soft keyboard show/hide event?

Is it possible to catch the event that Soft Keyboard was shown or hidden for EditText?
shkim
  • 1,173
  • 3
  • 16
  • 24
44
votes
4 answers

UISearchbar keyboard search button Action

I'm using UISearchBar when I input text on UISearchBar the keyboard shows. At that time, keyboard return key is "Search". I want to implement event when I press the keyboard search button. How can I implement the action? On UITextField it has…
Chenggong Jin
  • 531
  • 1
  • 4
  • 9
43
votes
3 answers

Alternative for event's deprecated KeyboardEvent.which property

MDN states that KeyboardEvent.which is deprecated. How can I substitute it for a non-deprecated version? For example, I have the following: window.onkeydown = (event) => { console.log(event.which); } I thought event.key.charCodeAt() could…
flen
  • 1,905
  • 1
  • 21
  • 44
41
votes
6 answers

Blazor, how can I trigger the enter key event to action a button function?

I was trying the todo-list example from Microsoft: https://learn.microsoft.com/en-us/aspnet/core/tutorials/build-a-blazor-app?view=aspnetcore-3.1 I want to add a todo item and instead of pressing the button with a mouse click I want to press the…
1
2 3
99 100