press enter key with a click?

I have a special mouse that its control is with the buttons. I mean that when I press left button focus go forward, when I press middle focus go behind and the right one press a click. It is not working good in some objets with the right button because sometines the website doesnt' recognize the click so I was thinking to change the clck with a enter key, I mean when I press the right button I want a key enter push. I don't know If I was very clear. This is the actual code:

$(":focusable").eq(0).focus();
var currentFocus=$(":focusable").eq(0);


$(document).ready(function(){
    $("#prueba1").mousedown(function(e){
    //1: izquierda, 2: medio/ruleta, 3: derecho         
    if(e.which == 3)                {
    //PlaySound3("http://www.soundjay.com/button/beep-06.wav");
    //PlaySound3("https://www.soundjay.com/button/button-30.wav");
    PlaySound4();
       if(currentFocus!=undefined){
        currentFocus.focus();
        currentFocus.trigger('click');

        if(currentFocus.prop('tagName')=='A'){
             window.location.href = currentFocus.attr('href');
        };
    }
    return false;           
    }
    if(e.which == 2)                {
    PlaySound3();
    var focusables= $(":focusable");
    var current= focusables.index(currentFocus);
    var previous = focusables.eq(current-1).length ? focusables.eq(current-1) : focusables.eq(0);
    currentFocus=previous;
    previous.focus();
    return false; 
    }
    if(e.which == 1)                {
        parar();
        PlaySound();
        //PlaySound3("http://www.soundjay.com/button/beep-07.wav");
    var focusables= $(":focusable");
    var current= focusables.index(currentFocus);
    var next = focusables.eq(current+1).length ? focusables.eq(current+1) : focusables.eq(0);
    currentFocus=next;
    next.focus();
    return false;    
    }
    });
    }); 

Thank u so much!

Upvotes: 0

Views: 761

Answers (1)

Burak Akyıldız
Burak Akyıldız

Reputation: 1644

Trigger enter key on right click like this.

var e = $.Event( "keypress", { which: 13 } );
$('#yourInput').trigger(e);

Upvotes: 1

Related Questions