How to use the hotkeys with Jquery?

3

I would like to know how to use the quick access keys in Jquery.

Currently for click events a button is used in this way:

 $("#id_boton").on('click', function (e) {
 //codigo ...
 });

In the case of the row of a datatable:

$('#idtable tbody').on('click', 'input.elimina_fila', function () {
 //codigo
});

but I would like to know for example when I press the A key, and also the F1, F2, F3 key. But also, when one presses the F1 key, there will be a browser tab (help), for that case, I would like to know how to block that action.

But in the case of the row of a table, as it would be. For example, in the row of the table, there is an input of type button that has a class called delete_file, where in the same input, there is a data-value and in the event, it received the value with this data, like this:

$('#idtable tbody').on('click', 'input.elimina_fila', function () {
var valor= $(this).data("valor");

});

As I would in the case that will position me in the row of a table and then press enter, where in the event, it captures the data's?

I would like to know how or what events I should use when I press a button, and when I am in the row of a datatable.

I hope I can have your help

    
asked by Danilo 28.03.2017 в 04:57
source

1 answer

2

To block the Quick Access key action as F1 would be like this. always changing the KeyCode of the key pressed. This page can help for get the KeyCode of a key

$(function() {
    $(document).on('keydown', 'body', function(event) {
        if(event.keyCode==112){ //F1
            event.preventDefault();
         }
     });
 });

If you want to prevent more than one key, taking into account that this example applies to the body if you want to do it in a input or another element, you would have to modify it indicating the ID or the Clase specified.

 $(function() {
    $(document).on('keydown', 'body', function(event) {
                    //cambiar body por input.elimina_fila por ejemplo
        var array= [112,113,114,115];//F1,F2,F3,F4
         if(array.includes(event.keyCode)) {
            event.preventDefault();
         }
     });
 });

For an Input of A table it would be something similar

$(function() {
    $('#idtable tbody').on('keydown', 'input.elimina_fila', function(event) {
                    //cambiar body por input.elimina_fila por ejemplo
        var array= [112,113,114,115];//F1,F2,F3,F4
         if(array.includes(event.keyCode)) {
            event.preventDefault();
         }
     });
 });
    
answered by 28.03.2017 / 05:03
source