reorx
V2EX  ›  问与答

javascript, simulate keyboard events, work on chrome(webkit)

  •  
  •   reorx · Jan 31, 2011 · 4606 views
    This topic created in 5659 days ago, the information mentioned may be changed or developed.
    in FF, i've used this code:

    74 if (keyCount == lineLimit) {
    75 // method in FF, no Chrome
    76 var mock = document.createEvent("KeyboardEvent"); // or KeysEvent
    77 mock.initKeyEvent("keypress",true,true,null,false,false,false,false,14,0);
    78 var x = document.getElementById('InputCategory');
    79 // rise height before Enter
    80 $(this).height(div_height + font_height + offset_height);
    81 // mock Enter
    82 x.dispatchEvent(mock);
    83 // init keyCount
    84 keyCount = 0;
    85 }

    it works, but could not be effective on webkit-based browsers like chrome.

    so i asked google and found keyboard event is one of the DOM Level 3 events,here is an aticle: http://www.w3.org/TR/DOM-Level-3-Events/

    then i knew /* initKeyboardEvent */ is not supported on chrome & safari, /* initUIEvent */ i've tried, it didn't work also.

    Do virtual keyboard events reall can be simulated on chrome ? plesase help me :)
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5209 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:08 · PVG 17:08 · LAX 02:08 · JFK 05:08
    ♥ Do have faith in what you're doing.