All keyup / keydown events in iframe?

I am working on a canvas-based game and use window.addEventListener() to add keyup and keydown events around the world. This works when viewing a page in normal mode, but when attached to it as an iframe; it does not receive keyup and keydown events. Is there a better way to do this?

+8
source share
2 answers

It seems you can just do var realWindow = window.parent || window; var realWindow = window.parent || window; and use addEventListener instead of realWindow .

+1
source

You cannot, unless the frame has focus.

What you can do is to make keydown in the external window the focus of the iframe or always somehow focus the iframe or configure the iframe by default (maybe good enough, not sure what you are doing)

But for a window keydown to run in any window (frame or not), focus is required for this frame.

+1
source

Source: https://habr.com/ru/post/917577/


All Articles