Key input and window focus

lockean's icon

Hey all,

I made a simple patch that uses a [key] object to convert keystrokes into MIDI CC messages. However, the patch only responds to keystrokes if its window is selected.

Is there a way to have the [key] object always listening for key inputs, even if MaxMSP doesn't have window focus?

Thanks in advance.

Gregory Taylor's icon

I'm sure that someone will correct me if I'm wrong, but I believe that there is no way that the key object will report key presses if Max doesn't have the focus - it's a prerequisite.

lockean's icon

Hmm... Fair enough.

Do you know of a way to keep MaxMSP in constant focus? I'm running Mac OSX 10.5.8.

If that question is not answerable, maybe another solution can be created. What I am attempting to do is use this patch with Mainstage 2. Essentially, the keyboard inputs will be used to switch my buttons in Mainstage on and off via MIDI CC messages. Is there another way I can do this... i.e. make the patch into an AU plug-in so I can run it in Mainstage?

Thanks for taking the time to consider this.

Luke Hall's icon

Try using the [hi] object, if you select your keyboard it should work even when the window is not the frontmost one.

lh

lockean's icon

Hm... something really fishy is going on.

So I used the [hi] object, and it seemed to work great... Mainstage receives MIDI input when I press the keypad buttons even when the Max patch window is not in focus.

But now when I use the keypad, the assigned buttons in Mainstage do not trigger. They work fine if I click the 'bang' button I have, and they work fine when I use the [key] object.

Is there something I'm missing about the [hi] component that could be causing this problem?

Like I said before, Mainstage seems to receive the message, but something about [hi] is interfering with the interface components.

I'm copying the patch down here. Anyone with Mainstage who can figure out what's going on?

(I know this probably should be a post on Apple's website, but MaxMSP users are generally more knowledgeable.)

Max Patch
Copy patch and select New From Clipboard in Max.

lockean's icon

Just an update:

Everything works if I hold another key down and then press the key desired.

I would prefer if I didn't need to do this... does anyone have a fix?

seejayjames's icon

[key] won't hear the keystrokes if Max isn't in focus. (and btw it doesn't have to be the patch with [key], just any patch or the Max window.) But Max will always hear MIDI in, so you could go that way with [ctlin]. If you want to use keystrokes, there are java solutions. check this thread:

there's a couple great java snippets that you can use in Max with [mxj] to listen for and/or generate key presses.

Tj Shredder's icon

To find out what the hi object is ending, hook up a print object...
It does not send only one message per key!

On my powerbook this will play the komplete upper row and the arrow keys:

Max Patch
Copy patch and select New From Clipboard in Max.