-- card: 11894 from stack: in.1 -- bmap block id: 0 -- flags: 0000 -- background id: 3468 -- name: -- part contents for background part 2 ----- text ----- PostEvent -- part contents for background part 8 ----- text ----- Dewi Williams -- part contents for background part 9 ----- text ----- XCMD -- part contents for background part 4 ----- text ----- PostEvent , - Tempo PostEvent - Quickeys -- part contents for background part 1 ----- text ----- 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! VIRTUAL KEYCODES: ------------------- 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 A S D F H G Z X C V res B Q W E R Y T 1! 2@ 3# 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 4$ 6^ 5% =+ 9( 7& -_ 8* 0) ]} O U [{ I P Return L J '" K ;: 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 \| ,< /? N M .> Tab Space `~ BackSp Enter Escape res Cmd Shift CapsLk 58 59 60 61 62 63 64 65 66 67 68 69 70 Option Control RShift ROpt RCntrl res unused . rt arr * unused + lt arr + 71 72 73 74 75 76 77 78 79 80 81 82 83 Clear dn arr unused unused / Enter up arr/ - unused unused = 0 1 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 2 3 4 5 6 7 unused 8 9 unused unused unused F5 F6 F7 F3 F8 F9 unused F11 104 105 106 107 108 109 110 111 112 113 114 115 116 unused F13 unused F14 unused F10 unused F12 unused F15 Help Home Page Up 117 118 119 120 121 122 123 124 125 126 127 Delete F4 End F2 PageDn F1 left arr rt arr dn arr up arr Reset