Register keyDownAction to IDE window?

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

It’s not theoretical – it exists!

Document.current.keyDownAction = { |... args| args.debug("typed") };

Document.current.keyDownAction = nil;

Document.globalKeyDownAction = { |... args| args.debug("typed") };

Document.globalKeyDownAction = nil;

(One difference, though, is that Qt GUI widgets’ key down action can override the default key action. IDE documents’ key down action involves IPC. From the IDE’s point of view, those actions are asynchronous, and it isn’t going to wait for the language to send back a “no don’t do the normal thing” message. So AFAIK you can respond to keys pressed in a document, but you can’t make the IDE respond radically differently to those keys.)

(Doesn’t apply to post or help windows.)

hjh

Thanks James, this is exactly what I was looking for. I skimmed the Document help file but clearly should have looked more closely.

Eli