We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Fake key press? (Read 588 times)
Fake key press?
Feb 3rd, 2008, 8:28pm
 
Is it possible to let processing fake a key press? Like, when two balls collide, it will make the computer think the A key was pressed, and an A would apear in, for example, word if that application would be in the front.
(That way I would be able to send commands to a VJ application)
Re: Fake key press?
Reply #1 - Feb 4th, 2008, 6:54am
 
You can split up the operations into a method, such as

Code:

void somethingHappened(char letter){
// do stuff
}


So in your keypressed

Code:

void keyPressed(){
somethingHappened(key);
}


And also in your collision

Code:

if(collide){
somethingHappened(whatHappened);
}
Re: Fake key press?
Reply #2 - Feb 4th, 2008, 7:58am
 
Look into the java Robot class.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html

It has a keyPress() method that should allow you to pass commands between apps.

But, because of this awesome power, the Java security manager is going to make it so that it only works as a local executable.

Re: Fake key press?
Reply #3 - Feb 4th, 2008, 9:49am
 
@mflux:
that doesn't fake a keypress in a way that I can pass it on to another application; it just adds an extra function, 'cause it would be just as easy to just call the function from within the collision function

@screamyguy:
Thank you; I'll look into it. I have no idea how to use 'real' java inside processing, but I'll try to figure it out
Re: Fake key press?
Reply #4 - Feb 4th, 2008, 11:56pm
 
My mistake I didn't catch the part you said about passing to a VJ software.

Depending on your VJ software though, could you potentially send it an XML or midi command? The same would apply.
Re: Fake key press?
Reply #5 - Feb 5th, 2008, 12:56am
 
I don't get it. How do you use 'real' java classes in processing? Like the java Robot class.

I'll think I'll just try Max/MSP. Video works faster in Max anyway :p
Page Index Toggle Pages: 1