add AWT-Event to Max-Application (for getting Keystrokes)
Hi guys!
I tried to build a mxk object, that ouputs all the kye strokes even if the Pathcer (M4L-device) doesn't have the focus.
(For the AWT.KeyEvent you would need to apply the EventListener to a UI-Object, so my idea was to add a general EventListener to the Max application and than ask wheather it's a KeyEvent.)
So here's my source code:
import com.cycling74.max.*;
import java.awt.AWTEvent;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.*;
public class getKeystroke extends MaxObject {
private static final String[] INLET_ASSIST = new String[]{
"inlet 1 help"
};
private static final String[] OUTLET_ASSIST = new String[]{
"outlet 1 help"
};
public getKeystroke(Atom[] args)
{
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});
setInletAssist(INLET_ASSIST);
setOutletAssist(OUTLET_ASSIST);
Toolkit tk = Toolkit.getDefaultToolkit();
tk.addAWTEventListener(new AWTEventListener() {
public void eventDispatched(AWTEvent e)
{
outlet(0,e.getID());
}
}, AWTEvent.KEY_EVENT_MASK );
}
public void bang()
{
outlet(0,"BANG ");
}
public void inlet(int i)
{
}
public void inlet(float f)
{
}
public void list(Atom[] list)
{
}
}
It doesn't work in Max (Max4Live). But the funny thing is when I edit the code via [mxj quickie]: Every keystroke that I make in the JAVA EDITOR is printed out in the MAX APPLICATION. strange, hm?!
Any advices are welcome!
Thanks,
simon