Changing the keypress

后端 未结 6 1151
北荒
北荒 2020-11-27 06:16

In an input box or contenteditable=true div, how can I modify a keypress for the letter \"a\" to return a keybress for the letter \"b\"? I.e., every time you type the letter

6条回答
  •  抹茶落季
    2020-11-27 06:57

    I'm not sure if this is "easily" do-able, with something like this:

    $(window).keypress(function(e) { 
        //Captures 'a' or 'A'
        if(e.which == 97 || e.which == 65)
        {
            //Simulate a keypress in a specific field  
        }
    });
    

    I do know that jQuery has a simulate plug-in to simulate keypress events etc, jQuery Simulate. It might be worth looking into - also possibly some type of jQuery Trigger() event.

提交回复
热议问题