Fix key recording by setWindow before capture starts.
It is common that during the construction of widget, it is not yet added to a window. Thus windowHandle will simply return null in this case. Always set the window to before the capture starts.
It is common that during the construction of widget, it is not yet added to a window. Thus windowHandle will simply return null in this case. Always set the window to before the capture starts.