Hi all, I’m trying to add a text-based visual component to a live coding improvisation session. My general idea is to do is place an invisible, fullscreen-sized window on top of the IDE, and define a keyDownAction that responds to keys pressed during the improv. A very basic example would be to display the pressed character in a StaticText object.
The problem I’m running into is that it seems like the window and the IDE both need to be in focus at the same time. If the IDE isn’t in focus, I can’t enter text into the IDE. If the visuals window isn’t in focus, the key presses don’t register, so the action isn’t called.
One theoretical solution would be to define a keyDownAction for the IDE window itself (I’m using the SC IDE), so that key presses would be entered text into the IDE, while also triggering an action function that could influence GUI elements on a separate window that’s not in focus. Is this possible? If not, is there a different approach that would accomplish what I’m trying to do?
This code is my starting point, for whatever it’s worth:
(
// press ESC to close invisible window
var win, text;
win = Window.new(\, Window.screenBounds, false, false)
.alwaysOnTop_(true)
.background_(Color(0, 0, 0, 0.3)).front;
text = StaticText(win, win.bounds.insetBy(600, 270))
.font_(Font(Font.defaultSerifFace, 500))
.string_("a")
.align_(\center)
.background_(Color.black.alpha_(0.1))
.stringColor_(Color(1, 1, 1, 0.1));
win.view.keyDownAction_({ |view, char, mod, uni|
if(uni == 27) { win.close };
text.string_(char);
text.bounds_(
Window.screenBounds
.insetBy(600, 270)
.moveBy(rrand(-600, 600), rrand(-300, 300))
);
});
)
Eli