catch-all keyup/keydown events in iframe?

前端 未结 2 1628
野的像风
野的像风 2021-01-12 04:51

I\'m working on a canvas-based game and am using window.addEventListener() to attach keyup and keydown events globally. This works in

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 05:14

    You can't, not unless the frame has focus.

    What you can do is make a keydown on the outer window focus the iframe, or always somehow focus the iframe, or focus the iframe by default (might be good enough, not sure what you're doing)

    But for the window keydown to fire on any window (frame or not) that frame needs focus.

提交回复
热议问题