Articles 3D Audio Custom Controls General RB Graphics Hacks Mac OS X Menus Novelty Printing REALbasic 2005 REALbasic 2006 Registration Resources Reviews Serial Speech Sockets XML Video Resource Links News Current News February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 ![]() REALbasic for Dummies by Erick Tejkowski ![]() Learning REALbasic through Applications REALbasic for Macintosh REALbasic Cross-Platform Application Development
Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander |
|
This week we'll take a break from the Merlin project and play with a newly released plugin. Totte Alm has created a fun REALbasic plugin that permits you to send key down events to any application. This is very useful for "faking" scripting of non-scriptable applications. Preparation Before you begin this project, you will need to download the T3 Key Plugin from Totte's site. When you have the plugin, drop it in your REALbasic Plugins folder. Note that this week's example only works on Mac OS X. When you're finished downloading and installing the plugin, launch REALbasic. Build the Interface The interface for this project is very simple. Drag a Timer control to Window1 and set is Period to 1000 and Mode to 2. That's it! Simple, huh? Add the Code The code example this week is also very easy to complete. It is based heavily on the project that accompanies the plugin, but simplifies matters a bit. Double click Window1 to open its Code Editor and add the following code to its Open event: LaunchGrabwhichcmd = 1 Next, open the Action event of the Timer control and enter this code: dim n as integerselect case whichcmd case 1 //press Cmd-Shift-Z //to start timed screenshot n = PostCommandKeyEvent(true) n = PostShiftKeyEvent(true) n = PostKeyEvent( "Z", &h06, true ) n = PostKeyEvent( "Z", &h06, false ) n = PostCommandKeyEvent(false) n = PostShiftKeyEvent(false) case 2 //press return to start the timer n = PostKeyEvent( "", &h24, true ) case 3 //quit app me.mode=0 quit end select //go to next step whichcmd=whichcmd+1 Then, select the Edit-New Property menu and create a new property as follows: whichcmd as Integer The final step for coding this example is to launch the AppleScript Script Editor and create a script like this: tell application "Finder"tell application "Grab" activate end tell end tell Save the script as a "Compiled Script", and name it LaunchGrab. Drag this script into your REALbasic application. You're ready to go! When you launch the application, it will in turn launch the Grab application, press Cmd-Shift-Z, followed by a tap on the Return key. This keyboard sequence causes the Timed Screenshot window to appear in Grab and start the process of a timed screenshot. The great part about this, though, is that this is impossible with AppleScript alone. It works as though you had typed the commands in by hand. The demo plugin stops working after a few minutes, but this doesn't matter for our simple example. We will be finished using it in a matter of seconds. And, if you're interested in more involved uses of the plugin, the price is very affordable. As you can imagine, this plugin has many interesting possibilities. Not only is it good for "scripting" previously unscriptable applications or features of applications, it has other uses. It wouldn't be terribly difficult, for example, to force a browser to launch, open a URL, and automatically login. Or, maybe you just want to play a trick on a friend. This plugin would help you out in such endeavors as well. In the future, we may use the plugin here at ResExcellence to demonstrate how to do a particularly confusing action in REALbasic. That way you can download a simple application which will guide you through the steps of a project. Fun stuff, indeed. Now, it's up to you to come up with an imaginative use for this powerful tool. Conclusion You can download this week's project and example application, in case you don't want to create the project by hand. Have fun and see you next week when we'll wrap up our Merlin project. |
||||
|
||||||||||||||||||||||||||||||||
Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.
[an error occurred while processing this directive]