This stack explains how to glue together Hypercard with the Tempo macro utility or the QuicKeys keyboard enhancer, using a XCMD resource called PostEvent. You'll need Tempo version 1.2 or QuicKeys 1.0, and System 4.1 or later.
Invoking QuicKeys sequences or Tempo macros from within Hypercard can be quite useful. You can do the following:
ΓÇó Fill in any cracks in the HyperTalk programming language.
ΓÇó HyperTalk won't let you issue click commands for dialog boxes (e.g. the
printing ones).
ΓÇó HyperTalk won't let you invoke desk accessory menu items via doMenu.
• If you have a "minifinder" card in your Home stack, you can launch
applications under the control of a sequence or macro.
HYPERCARD & TEMPO:
---------------------
The PostEvent command allows a script to post a keydown event with arbitrary modifiers (Option, Command, Shift, Caps Lock or any combination of these). If there is a Tempo macro corresponding to this key combination, then it should run.
PostEvent is called like this for Tempo:
PostEvent modifier,virtual keyCode
For instance, the following call posts an option-w:
PostEvent "O",13
(where the first argument is an upper-case "Oh", not a zero).
A “virtual keyCode” is a keyboard-independent method of identifying a keystroke.
HYPERCARD & QUICKEYS:
------------------------
This isn't as ugly as the Tempo interface. You can specify the name of the QuicKeys sequence or click that you want to run as a single parameter:
PostEvent "Reformat"
will run a click or sequence that you had previously given that name. PostEvent will accept the first match that it can find, checking the Hypercard-specific keys first, and then the Universal ones. If it can't find a match, it will beep once.
The Tempo interface will also work with QuicKeys. You might want to do this to issue a command key to a desk accessory, for instance. For QuicKeys only, a control key modifier can be specified in the first argument – use a lower case "c".
TEMPO & QUICKEYS:
-------------------
QuicKeys and Tempo seem to coexist, though I haven't pushed my luck. The PostEvent command needs to know which one you're using, and uses the following rules:
1. If you call PostEvent with only one argument, then it's a QuicKeys sequence or
click name.
2. If you call with 2 arguments, PostEvent checks for a Hypercard global variable
called "Macro". If this global contains the string "Tempo", then Tempo's used. If
the global doesn't exist, or holds some other name, then QuicKeys is used.
Putting the following handler in the card script should be sufficient:
on openCard
global Macro
put "QuicKeys" into Macro
end openCard
RUNNING A CONTROLLED APPLICATION:
------------------------------------
PostEvent doesn't immediately invoke a sequence or macro. Instead, it posts a "key down" event for later consumption by Hypercard. So a HyperTalk fragment like the following won't work:
PostEvent "InitRulers"
open "MacWrite"
because nobody will see the event. The trick is to have the sequence or macro already running when you issue the open command. I use the following trick:
Create an invisible button called "Macro". Every sequence starts by clicking on its location. It has the open command in its mouseUp handler (if necessary the application name can be saved in a global variable). Then the following fragment can be used:
set the hilite of button "Macro" to true -- show it
PostEvent "InitRulers"
and the sequence will take over. In QuicKeys, the sequence and its components will have to be Universal, not program-specific.
MODIFIER VALUES:
-----------------
• Command: C
• Shift: S
ΓÇó Caps Lock: L
• Option: O
Concatenate the modifiers to get the required combination. For instance, "SO" is Shift-Option. One note of caution: Command-Option combinations are tricky to test under HyperCard because these two keys are used as a ΓÇ£reveal buttonsΓÇ¥ function. Try it and see!