1

I am trying to fire keydown event using synthetic new KeyboardEvent() on Microsoft Edge (not IE) browser but not able to set keyCode property. Actually, I want to simulate down arrow keydown event.

const event = new KeyboardEvent('keydown', {
          code : 'Down',
          key: 'Down',
          keyCode: 40,
        } as KeyboardEventInit));

but when I dispatch this event and logs the output event, the keyCode property always returns to be 0 instead of 40.

The above code works on Chrome, Firefox, and Safari. Correct me if I am doing anything wrong.

Yushin
  • 1,684
  • 3
  • 20
  • 36
Usman Saeed
  • 211
  • 1
  • 8
  • Behavior confirmed. – Yarl Mar 14 '19 at 09:58
  • You can try experiments with initEvent(). See https://technet.microsoft.com/en-us/windows/dn905219(v=vs.71), https://stackoverflow.com/questions/30003774/simulate-enter-in-javascript. – Yarl Mar 14 '19 at 10:18
  • looks like this issue only occurs with (synthetic) Keyboard event. I made a test with JS code and it is working fine with MS Edge. – Deepak-MSFT Mar 15 '19 at 05:24

1 Answers1

0

Regard MDN KeyboadrEvent constructor compatibility is unknown for EDGE.

Yarl
  • 728
  • 1
  • 7
  • 26