Is it possible to have keyDownAction to work without having to .front the window?
There’s probably two separate things here:
-
.front
causes theView
to be displayed (e.g. before calling.front
the View is invisible) -
.front
causes theView
to gain focus and move to the top of the OS stack of windows.
keyDownAction
won’t work without #1 because before this, the View basically doesn’t exist. QT knows about it’s properties, but it hasn’t actually created anything.
keyDownAction
won’t work without #2 because generally the OS routes keyboard events to whatever window / view has focus and is topmost.
There may be some ways to get what you want though? A couple ideas:
- You CAN make a window show up on top of other windows even if it doesn’t have focus, using the
alwaysOnTop
property. This would mean you could have a window that is visually below that window, but is still the receiver of keyboard events (you’d still have to callfront
to focus that window, but it wouldn’t be visually in front of the other one). -
View
hasglobalKeyDownAction
andglobalKeyUpAction
, which should get called when ANY view receives a keyboard event. If you want to have a sort of universal override for all keyboard events, this is the place for it.
If you set View.globalKeyDownAction (View | SuperCollider 3.12.2 Help) then the action seems to run as long as you have one SC window selected, it doesn’t matter which one as it’s not linked to a particular window.
Of course, it won’t run if you have another application selected.
(
View.globalKeyDownAction = {"Key was pressed.".postln;};
Window.new("Win 1").front;
Window.new("Win 2").front;
)
Best,
Paul
Edit: sorry I missed @scztt 's reply