I have a function which detect max length. but the problem is that when the max length reached Ctrl+A combination does't work. How can I detect Ctrl+A combination through javascript.
This is my maxlength code.
if (event.keyCode==8 || event.keyCode==9 || event.keyCode==37 || event.keyCode==39 ){
return true;
} else {
if((t.length)>=50) {
return false;
}
}
Using JavaScript In plain JavaScript, you can use the EventTarget. addEventListener() method to listen for keyup event. When it occurs, check the keyCode 's value to see if an Enter key is pressed.
Examples of modifier keysOn an IBM compatible computer, modifier keys include Alt, Ctrl, Shift, and the Windows key. On the Apple Macintosh computer, the Control, Option, Command, and Shift keys are modifier keys. Additionally, most laptop and some desktop keyboards contain an Fn modifier key.
On a Windows keyboard, the modifier keys are Shift, Alt, Control, and the Windows key. On a Mac keyboard, the modifier keys are Shift, Control, Option, and Command (often called the Apple key).
Check event.ctrlKey
:
function keyHandler(event) {
event = event || window.event;
if(event.keyCode==65 && event.ctrlKey) {
// ctrl+a was typed.
}
}
key codes:
shift 16
ctrl 17
alt 18
your jQuery:
$(document).keydown(function (e) {
if (e.keyCode == 18) {
alert("ALT was pressed");
}
});
JavaScript Madness: Keyboard Events
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With