problem with "system events" pressing a key

Hi everybody here

I’m a beginner in Applescript, so maybe this question could seem foolish but … i need help

I need to use this application : reactivision.sourceforge.net/ , and i need it to open up at start up when i launch my mac.
Until here, everything ok, using this script :

tell application "reacTIVision"
	launch
end tell

Now, in this app i would like to automate the following action : i need to open the options menu (key “O”) and to change to another device (key up). This, because the webcam i need to use with this app is an external usb one)

In fact i need to do this :


	tell application "System Events" to keystroke "O"
	tell application "System Events" to key code 126 (keyup - to select the right device)
	tell application "System Events" to key code 36 (enter)

but when entering this script, it doesn’t work at all. So i thought : too quick for the “reactivision” app to respond. So, i thought of using either


      considering application responses

or


	with timeout of (let's say) 5 seconds

But none of these script do work. No response from the keyboard, only the app starts and that’s all.
So i’m stuck here, and i dunno what’s wrong as i am a complete noobie.

Any help would be strongly appreciated. Thanks

Keystrokes happen on the frontmost active application. So your tell application “reacTIVision” to launch code does no good. Launching an application makes it open in the background. The app needs to be frontmost and active, so use tell application “reacTIVision” to activate just before you perform any keystrokes.

THANK YOU !

Works fine :slight_smile: