LoginSignup
0
0

More than 3 years have passed since last update.

IE11 の initKeyboardEvent の使い方

Last updated at Posted at 2019-06-10

やり方をいつもすぐに忘れてしまうので、備忘録として書いておく。今更感満載だけど、未だに需要があるので。

MDN の Keyboard​Event​.init​Keyboard​Event()ページではダメ。

technet とか MSDN を見ないといけない。

    const keyevent = {
      keydown: 'keydown',
      keypress: 'keypress',
      keyup: 'keyup'
    };

    const key_ie = {
      Backspace: 'Backspace',
      Tab: 'Tab',
      Enter: 'Enter',
      Shift: 'Shift',
      Control: 'Control',
      Escape: 'Esc',
      Space: 'Spacebar',
      End: 'End',
      Home: 'Home',
      ArrowLeft: 'Left',
      ArrowUp: 'Up',
      ArrowRight: 'Right',
      ArrowDown: 'Down',
      Delete: 'Del',
    };

    // 半角スペースで区切る
    const modifiers = 'Alt Control Shift';

    const event = document.createEvent('KeyboardEvent');

    // https://technet.microsoft.com/en-us/windows/ff975297(v=vs.60)
    event.initKeyboardEvent(
      keyevent.keydown,
      true,
      true,
      document.defaultView,
      key_ie.Tab,
      0,
      modifiers,
      true,
      ''
    );

    elem.dispatchEvent(event);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0