Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should I use keydown and keyup?

Which event should be used for key press handling key-down/key-up? It is sure that in both case the program will run successfully. But which one will be more user-friendly?

like image 784
Nafeez Abrar Avatar asked Oct 24 '12 13:10

Nafeez Abrar


People also ask

What is difference between keypress and Keydown and Keyup event?

The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .

What is the use of Keyup function?

The keyup() is an inbuilt method in jQuery which is used to trigger the keyup event whenever User releases a key from the keyboard. So, Using keyup() method we can detect if any key is released from the keyboard.

What is difference between Keyup and Keydown in jQuery?

jQuery keyup() Methodkeydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.

What is the use of Keydown event?

The onkeydown attribute fires when the user is pressing a key (on the keyboard).


1 Answers

It depends on you. There is no such best practice. Both are used as per the need of your program and as per the convenience of the user.

keyup Fires when the user releases a key, after the default action of that key has been performed.

keydown Fires when the user depresses a key. It repeats while the user keeps the key depressed.

Check out this page describing the differences.

like image 110
Rahul Tripathi Avatar answered Nov 13 '22 18:11

Rahul Tripathi