3
To add a new item in my database there is the button Add, however I would like to add a shortcut for you to perform the same function as the button. For example when the And in any question in the OS, this same goes into editing mode.
In my case I thought something like Shift + N to insert a new item.
Using the keydown
it is possible to detect that only one key has been pressed, as shown in the example below:
$(document).keydown(function (e) {
if (e.keyCode == 16) {
alert("O código "+ e.which + " que representa o Shift foi precionado");
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
To create the shortcut I thought something like:
if (e.keyCode == 16 && e.keyCode == 78)
That in this case the 78
corresponds to the n, but it didn’t work that way.
How could I create a shortcut on my web page that would recognize the command shift+n?
It worked like this man, you can tell me why it didn’t work like that:
if (e.keyCode == 16 && e.keyCode == 78)
whereas keycode 16 refers to shift ?– viana
@Acklay edited my answer with a compliment and created a fiddle to test these scenarios. Hugs
– mrlew
Great example +1
– Leonardo Rodrigues