Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable keyboard shortcut in textarea

I am using something like this:

jQuery(document).keydown(function(e){
  // code
}

For switching photos in photoalbum with arrow keys.. It works great, but! I want to disable in textarea. Because, if I am commenting a photo and I want to move cursor with arrow keys, I switch photo and lose my text :)

How to disable it? Can I catch, which element is focused? Thank you

like image 427
Blaskovic Avatar asked Dec 02 '11 23:12

Blaskovic


People also ask

Can you disable a keyboard shortcut?

Navigate to User Configuration > Administrative Templates > Windows Components > File Explorer. Double-click on the Turn off Windows Key Hotkeys option on the right-hand side.

How do I disable keyboard bindings?

Select “System Preferences.” Select “Keyboard” from the list on the left side of your screen. Click on “Shortcuts” in the list of settings across the top of the window. Once inside “Shortcuts,” uncheck the box next to each shortcut to disable it.

How do I disable keyboard shortcuts in Visual Studio?

If you select a command that is bound to a shortcut, within the 'Keyboard' section of the Visual Studio Options dialog, the 'Remove' button should activate. Notice that the 'R' is underlined (which, if isn't, hold the Alt key down).


1 Answers

You can check to see if the target element is a textarea.

jQuery(document).keydown(function(e){
    var target = e.target || e.srcElement;
    if ( target.tagName !== "TEXTAREA" ) {
        // code
    }
});
like image 82
Will Avatar answered Sep 19 '22 01:09

Will