javascriptkeyboarddom-eventscase-sensitivecapslock

Is it possible to trigger a keyboard button with JavaScript?


Is it possible to trigger a keyboard button with JavaScript, and to get a input-case depending on the Caps Lock button?

So, if my Caps Lock is on, "IT SHOULD BE UPPERCASED" or "it should be lowercased if it's off".


Solution

  • Trigger an key event:

    var ev = jQuery.Event("keypress");
    ev.ctrlKey = false;
    ev.which = 37;
    $("container").trigger(ev);
    

    Hope that helps.