Domanda

For example, I have an input tag like:

<input type="file" id="upload" multiple="true">

Is this possible to choose files by setting a hotkey instead of clicking on input element?

È stato utile?

Soluzione

$(document).on("keydown", function(e){
    e = e || window.event;
    var keyCode = event.keyCode;   // code of the key pressed

    if(e.ctrlKey){             // if control key is pressed
        if(keyCode == 13){     // if current key is "enter" key
            $("input[type='file']").trigger("click");  // trigger click event
        }
    }
});

DEMO

Here's a list of all key codes.

Altri suggerimenti

using document.keyup check out this fiddle, try clicking ctrl + i

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top