home *** CD-ROM | disk | FTP | other *** search
/ Boot Disc 8 / boot-disc-1997-04.iso / PDA_Soft / Psion / misc / Kmac / KMAC.TXT < prev    next >
Text File  |  1994-04-25  |  56KB  |  1,311 lines

  1. KMAC.APP, the keyboard macro record and playback app
  2. ====================================================
  3.  
  4. Introduction
  5. ------------
  6. KMAC.APP allows you to automate many features of your S3a.  KMAC can
  7. be used to
  8.    * record keyboard macros
  9.    * play back these keyboard macros later
  10.    * edit your keyboard macros to add in extensive control features
  11.    * automate "demo" programs
  12.    * automate interactive tutorial programs
  13.    * simplify automated testing of programs (eg regression testing)
  14.  
  15. KMAC is designed to work as non-intrusively as possible.  It doesn't
  16. have its own "screen"; instead, it shares the screen of the current
  17. foreground application.
  18.  
  19. There's no need to transfer to another screen to start recording
  20. a macro.  Just press Shift-Control-Space ("Space" for "Start
  21. recording" - the same as in the built-in "Record" application), give
  22. the name of the macro you want to record (and, optionally, a hot-key
  23. for it), and then start pressing the keys you want recorded.  (As
  24. well as being recorded, the keys also have their normal effect - so
  25. you can see how far you've got through your intended sequence.)  When
  26. you're finished, press Shift-Control-Space again.  Then when you want
  27. to replay this macro at a later date, just press Shift-Control-Enter
  28. ("Enter" for "Start playback" - the same as in the built-in "Record"
  29. application).  Hey presto, the key sequence is replicated exactly.
  30.  
  31. In case you forget these special hot-key combinations, just press
  32. Shift-Control-Help, which brings up KMAC's own Help screen.  The only
  33. thing you need to remember is that the KMAC system uses the
  34. Shift-Control modifier pair as its own special prefix.  Then as the
  35. Help screen reminds you, you use
  36.  
  37.    Shift-Ctrl-Space          to start or stop macro recording
  38.    Shift-Ctrl-Enter          to play back the last macro recorded
  39.    Shift-Ctrl-Diamond        to select another macro to play back
  40.    Shift-Ctrl-A through Z    to play back the macro with this hot-key
  41.    Shift-Ctrl-Menu           to review existing hot-key assignments
  42.    Shift-Ctrl-Esc            to interrupt a macro playing back
  43.    Shift-Ctrl-Help           to show the KMAC Help screen
  44.  
  45. (You are also asked if you want to see this Help screen every time
  46. you start KMAC, so there's no need even to remember Shift-Ctrl-Help.) 
  47.    
  48. KMAC stores all its macros in a plain text file.  You can edit the
  49. contents of this file to add in extra control features, such as
  50.  
  51.     skip the next line if there's no dialog showing
  52.     stop unless a certain app (eg the Word Processor) is foreground
  53.     make any given application (eg the System Screen) foreground
  54.     load in another script file and take commands from that instead
  55.     loop back to the top of the present macro or script file
  56.     pause briefly (eg to allow the screen to redraw)
  57.     pause until the user "nudges" playback forwards again
  58.     switch into "single stepping mode" (useful for "debugging")
  59.     "bring" data from a background application
  60.     display "info messages" in the foreground application
  61.     present query or alert dialogs in the foreground application
  62.  
  63. If you understand Opl, you can write Opl programs that macros can
  64. start, and inside these programs, you can do even more complicated
  65. data manipulations and utilise all the features of Opl to control
  66. macro playback.  KMAC can also be used to start programs written in
  67. C, and you can even arrange for the foreground application to start
  68. running code from a specified DYL (which can have some very powerful
  69. results).
  70.  
  71. Although you can do very powerful things with KMAC (and the length of
  72. this documentation provides something of an indication of this), you
  73. don't need to work hard and long at it before you can achieve some of
  74. these results for yourself.  You don't need to know Opl, nor any
  75. other programming language.  Nor is there any special requirement for
  76. you ever to look at any of the .KMA (keyboard macro text files)
  77. produced by KMAC.  You can record and playback your first macro
  78. literally seconds after copying the KMAC files onto your S3a.
  79.  
  80. Disclaimers
  81. -----------
  82. KMAC is not an official Psion product.  You can not receive any
  83. assistance with it by contacting Psion Technical Support, or any
  84. other department within Psion.  However, if you ask a question about
  85. KMAC in the PSION conference on CIX, I will endeavour to answer it
  86. within a few days (within reason).
  87.  
  88. KMAC is reasonably well tested but I cannot take any responsibility
  89. for any problems you may encounter with your S3a as a result of using
  90. it.  KMAC exercises the software system on the S3a very fully and can
  91. sometimes expose limitations of that software that are not otherwise
  92. noticeable.  However, despite these shortcomings, I have no doubt
  93. that an S3a running KMAC is an even more powerful "personal
  94. assistant" than one *not* running KMAC.
  95.  
  96. Files in KMAC091.ZIP
  97. --------------------
  98. KMAC.TXT        This documentation
  99. KMAC.APP        The app itself
  100. LPC.DYL         Local Process Control DYL (used by KMAC)
  101. KMAC.DBF        Database of syntax of keywords understood by KMAC
  102. KMACED.ALS      Sample text editor for editing KMAC scripts
  103. EGKMA.TXT       Discussion of some example macros
  104. KMACLIB.OPO     Module to LOADM to access LPC from Opl programs
  105. KMACLIB.OPL     Source code for KMACLIB
  106. OPLLPC.TXT      Documentation on using LPC.DYL from Opl
  107.  
  108. For those who would like to look at it, the source code for KMAC.APP
  109. and LPC.DYL is available in separate zip files, KMAC091S.ZIP and
  110. LPC091S.ZIP.  (This source code is in C and requires version 2 of the
  111. C SDK to build it.  It also assumes, in place, knowledge of the
  112. object-oriented manner of operation of HWIM applications.)
  113.  
  114. Installing KMAC
  115. ---------------
  116. Copy KMAC.APP into an \APP\ directory on your S3a.
  117. Copy LPC.DYL into a \DYL\ directory on your S3a.
  118.  
  119. These are the only two files that you HAVE to copy onto your S3a,
  120. though you may also find it convenient to copy at the same time
  121.    KMAC.DBF into a \DAT\ directory
  122.    KMACED.ALS into an \APP\ directory
  123.  
  124. In the System Screen, use the "Install" option and select "Kmac" from
  125. the disk you copied it onto.  An icon will be added to the System
  126. Screen that it similar to (but noticeably different from) the icon of
  127. the sound "Record" application.
  128.  
  129. Press ENTER with the highlight on "Kmac" under the Kmac icon.  The
  130. word "Kmac" will change into bold text, showing that the Kmac
  131. application is running, but the System Screen remains in foreground.
  132.  
  133. (If you get an error instead, such as "File does not exist", check
  134. that the file LPC.DYL is in a \DYL\ to-level directory.)
  135.  
  136. A dialog will be shown, displaying
  137.    The version number of KMAC, and its release date
  138.    A copyright message
  139.    A pair of action buttons: Esc for "Continue" and Enter for "Help".
  140.  
  141. Normally, when starting KMAC you will press Esc to make this dialog
  142. go away.  But sometimes you may wish to press Enter to view the Help
  143. screen (described earlier in this document).
  144.  
  145. Later, when you want to exit KMAC, come back to the System Screen (if
  146. necessary), put the highlight on the word "Kmac" under its icon, and
  147. press Delete.
  148.  
  149. Recording your first keyboard macro
  150. -----------------------------------
  151. If necessary, start KMAC, and press Esc to clear the start-up dialog.
  152. If you are not there already, go to the System Screen.
  153.  
  154. Now let's record a macro to set the keyclick volume to "Quiet".
  155.  
  156. Start by pressing Shift-Ctrl-Space.  This brings up a dialog asking
  157. you to give the name for the keyboard macro you want to record.  Type
  158. in any name (this can be up to 23 characters long), eg "Set keyclick
  159. quiet", and press ENTER.  You are now in recording mode.
  160.  
  161. Press Psion-s to display the "Set the sound" dialog.  Press DOWN
  162. three times, to highlight the "Key click" line.  Press Q, to select
  163. "Quiet" from the choice list.  (Nothing will change on the screen if,
  164. perchance, the setting is already "Quiet".)  Press ENTER to confirm
  165. the dialog.
  166.  
  167. Now press Shift-Ctrl-Space to finish recording.  A special info
  168. message is displayed at the top left corner of the screen, confirming
  169. the name of the macro, and the number of keypresses in it (6 keys in
  170. this case).
  171.  
  172. Playing back this macro
  173. -----------------------
  174. In order to see the effect of this macro, manually set the keyclick
  175. back to loud.  Move the cursor around a bit, and listen to the loud
  176. keyclick.
  177.  
  178. If necessary, start KMAC, and go to the System Screen.  Then press
  179. Shift-Control-Enter.  (You don't need to put the highlight back on
  180. "Kmac" first.  Kmac captures this key combination, regardless of
  181. where the cursor is.)
  182.  
  183. There is a flurry of activity in the middle of the screen, and then
  184. an information message is shown at the top left corner: "Playback
  185. successful".  Move the cursor around a bit and you'll hear how the
  186. keyclick has indeed gone quiet again.
  187.  
  188. Revising the hotkey for a macro
  189. -------------------------------
  190. Press Shift-Control-Menu.  This brings up the KMAC "Revise hot key"
  191. dialog.  This shows a choice list of all the macros you have recorded
  192. so far, together with their hot-key.  You'll see that the macro you
  193. have just recorded has the hot key "[M]" shown for it (at the end of
  194. its name).  Let's change this to [Q], as follows:
  195.  
  196. Press ENTER to confirm that we want to change the hotkey of the macro
  197. shown.  Then press Q to select "Q" in the choice list of possible
  198. hotkeys shown in the next dialog.  Press ENTER to confirm this
  199. choice.  If you press Shift-Control-Menu at this stage, you'll see
  200. that the hotkey for your macro has indeed been changed.
  201.  
  202. By default, all new macros get assigned the hotkey [M].  Since Ctrl-M
  203. and Ctrl-Enter produce identical keycodes (13 in each case) and
  204. have identical modifiers, this means that Shift-Ctrl-Enter runs the
  205. macro with hotkey [M].  (But once you've revised the hotkey from [M]
  206. to [Q], the macro can no longer be played back by Shift-Ctrl-Enter.)
  207.  
  208. At this stage, you should probably experiment by recording several
  209. other macros and playing them back - either using Shift-Ctrl-Enter,
  210. or using Shift-Ctrl-<hotkey>, or by using Shift-Ctrl-Diamond and then
  211. selecting the macro to playback by name.
  212.  
  213. Note that you cannot record, in a macro, a keypress that takes you
  214. from one application to another - such as pressing a task key.  The
  215. recorder facility within KMAC is limited to recording keypresses in
  216. only one application at a time.  (But see later in this document for
  217. how to create macros that DO switch from one application to another.)
  218.  
  219. Macros are saved to file
  220. ------------------------
  221. When you exit KMAC - by pressing Delete with the highlight on "Kmac"
  222. in the System Screen - the macros are written out to a plain text
  223. file.  You can, if you wish, create several different files of
  224. macros, eg by using the "New file" option in the System Screen.
  225.  
  226. You can use the supplied word processor alias KMACED.ALS to look at
  227. these .KMA macro files.  (Alternatively, just use the "Create new
  228. list" option in the System Screen to create your own text-mode alias
  229. for the word processor, for \KMA\*.kma files.)  You may find it
  230. easiest to set the zoom setting to the smallest font (and then to
  231. save this as the default template for these files - but be sure to
  232. remove the text before you do this).
  233.  
  234. Note that changes in macros are only written to file when KMAC is
  235. exited (or receives a "switch files" instruction from the System
  236. Screen).  Watch out, in particular, that if you have the .KMA file
  237. open in an editor, and then try to exit KMAC, it will not be able to
  238. do so, if there are changes that have to be written to file.  Exit
  239. the editor first and then KMAC.  Likewise if you want any changes you
  240. make (by hand-editing) in a .KMA file to be picked up by KMAC, you
  241. have to exit KMAC first and then restart it.
  242.  
  243. The format of .KMA files
  244. ------------------------
  245. You'll be able to see that .KMA files consist of a brief header
  246. portion followed by a series of macro definitions.
  247.  
  248. The header section always starts with the line
  249.     KMAC 1.00
  250. and KMAC will refuse to load a KMAC file that does not start in this
  251. way.
  252.  
  253. After this, one or more of the two following lines may also be present
  254. in the header section:
  255.  
  256.     AUTO x
  257. defines what hot-key, if any, should be given to all new macros.  By
  258. default, x has the value "M".  You can put "?" instead, to force KMAC
  259. to ask you to supply a hotkey every time, immediately after recording
  260. a new macro.  Or you can put "-", so that new macros are left without
  261. any hot key defined for them.
  262.  
  263.     QUIET   
  264. specifies that any new macro recorded is automatically "quiet" (see
  265. below for the significance of this).
  266.  
  267. The definition of an individual macro
  268. -------------------------------------
  269. Individual macro definitions alway start with the line
  270.  
  271.     MACRO <name>
  272. which also specifies the name of the macro.
  273.  
  274. After this, there can be a few lines specifying additional
  275. information about the macro; then there is the "CONTENTS" section for
  276. the macro.
  277.  
  278. Before the contents section, the following lines can appear:
  279.  
  280.     KEY x
  281. which specifies the hot key of the macro, eg "KEY T" to specify the
  282. hotkey Shift-Ctrl-T
  283.  
  284.     QUIET
  285. which specifies that the macro is "quiet", meaning that the info
  286. message "Play back successful" does NOT get displayed at the end of
  287. the macro playback
  288.  
  289.     BACKGROUND
  290. which specifies that the macro does not start off by automatically
  291. "attaching" to the foreground application (see below for the
  292. significance of this).
  293.  
  294. The contents section must always start with the keyword "CONTENTS"
  295. and continues either until there is a blank line or the end of the
  296. file is reached.  The contents themselves are sequences of two types
  297. of commands:
  298.  
  299.     1. raw keycodes (together, optionally, with modifiers)
  300.     2. alphabetic commands (see below for examples).
  301.  
  302. In all, there are over 40 different alphabetic commands, such as
  303.     "G" to ensure the attached process is in its "ground state"
  304. (without any menu or dialog showing, etc - the macro ensures this is
  305. the case by sending as many Esc keys as are required)
  306.     "I" to display a specified information message
  307.     "J" to jump a given number of steps in the macro, if a certain
  308. condition is true (for example, if there is a dialog showing)
  309.     "S" to send a specified string of keys (this can be easier to
  310. understand than just seeing the raw keycodes)
  311.     "s" to adjust the "single stepping state" of the macro.
  312.  
  313. Evidently, the case of the first letter of the command is
  314. significant.  The "S" and the "s" commands are completely different.
  315.  
  316. The database file KMAC.DBF gives summary info about each of these
  317. "alphabetic" commands.  These commands are also discussed in more
  318. detail in the remainder of this documentation.
  319.  
  320. The only way alphabetic commands can appear in a macro is if they are
  321. edited in via an editor (such as KMACED).  There is no facility to
  322. enter them midway through recording a macro (though, clearly, they
  323. can be added in after finishing recording the "basics" of a macro).
  324.  
  325. You can also add in comments, which are lines starting with the
  326. exclamation mark character, "!".
  327.  
  328. There is a limit of around 3000 characters for an in-memory macro. 
  329. For longer macros, you have to put some of the contents into a
  330. separate file, and then load that file during playback, eg using the
  331. "l" command.
  332.  
  333. Introducing alphabetic commands
  334. -------------------------------
  335. The macro "Set keyclick quiet" described earlier is saved to file as
  336. follows:
  337.  
  338.     MACRO Set keyclick quiet
  339.     KEY Q
  340.     CONTENTS
  341.     627 8, 257, 257, 257, 113, 13
  342.  
  343. There is one problem with this macro, however.  If you press
  344. Shift-Control-Q when you are in an application other than the System
  345. Screen, it will have quite the wrong effect.  There is nothing in the
  346. macro itself to tie it to the System Screen.  In fact, by default,
  347. all KMAC macros attempt to "attach" to the application that is in
  348. foreground when they are invoked.
  349.  
  350. A simple way to fix this would be to edit the macro (using eg KMACED)
  351. to add in the line
  352.     gSystem
  353. as the first "contents" of the macro.  Thus the macro definition
  354. becomes
  355.  
  356.     MACRO Set keyclick quiet
  357.     KEY Q
  358.     CONTENTS
  359.     gSystem
  360.     627 8, 257, 257, 257, 113, 13
  361.  
  362. (Remember that you will have to restart KMAC for any changes made in
  363. a top-level macro to have an effect.)
  364.  
  365. If you also have a macro for setting the keyclick loud, you should
  366. make the corresponding change to it as well.  Then you can go into an
  367. application such as the calculator, and change the keyclick volume
  368. setting between Quiet and Loud at will, just using a single key
  369. combination each time, without having to task to the System Screen.
  370.  
  371. This macro uses the "go to" command, with letter "g".  It specifies
  372. that the macro should "go to" the first application it finds with the
  373. given name for display in the Status Window.  (The operation of "g"
  374. is more subtle than you might at first expect.  Eg to "go to" the
  375. instance of the "Data" application that has the file "Data.dbf" open,
  376. you would need to specify "gData.dbf".  See later for a fuller
  377. discussion of how the "g" command works.)
  378.  
  379. Note that if you play back this macro from an application other than
  380. the System Screen, the System Screen does NOT become foreground (ie
  381. come to the front) as a result.  The dialog interaction takes place
  382. with the System Screen entirely in the background.  Which makes for a
  383. neater screen display.
  384.  
  385. If you wanted to make the System Screen come to the front, while the
  386. macro was played back, you could follow the "g" command with an "F"
  387. command - the command that brings the attached application to
  388. foreground.  In this case, the macro could become
  389.  
  390.     MACRO Set keyclick quiet
  391.     KEY Q
  392.     CONTENTS
  393.     gSystem
  394.     F
  395.     627 8, 257, 257, 257, 113, 13
  396.  
  397. As another idea, you could put a "B" at the end of this macro - to
  398. put the System Screen into background again after processing the
  399. string of keys.  But frankly, whilst the "F" and "B" commands can be
  400. very useful in many places, this particular macro is not one that
  401. benefits from their presence.
  402.  
  403. Information messages during macro playback
  404. ------------------------------------------
  405. A better suggestion for improving the above macro is to change it to
  406.  
  407.     MACRO Set keyclick quiet
  408.     KEY Q
  409.     QUIET
  410.     CONTENTS
  411.     ISetting keyclick to quiet
  412.     gSystem
  413.     627 8, 257, 257, 257, 113, 13
  414.  
  415. and its "partner", "Set keyclick loud", could become
  416.  
  417.     MACRO Set keyclick loud
  418.     KEY L
  419.     QUIET
  420.     CONTENTS
  421.     ISetting keyclick to loud
  422.     gSystem
  423.     627 8, 257, 257, 257, 108, 13
  424.  
  425. This introduces the "I", or "Information message" command.  Try these
  426. and see what their effect is.
  427.  
  428. Note that the keyword "QUIET" has been added to these macros, in
  429. between their name definitions (the "MACRO" line) and the start of
  430. their contents (the "CONTENTS" line).  This has the effect of
  431. suppressing the "Play back successful" info message that would
  432. otherwise overwrite the macro's own "Setting keyclick..." information
  433. message.
  434.  
  435. Clarifying the notion of the "attached process"
  436. ---------------------------------------------------
  437. If you go to the Calculator and press Shift-Ctrl-L to play back the
  438. "Set keyclick loud" macro, and immediately start pressing the Up and
  439. Down cursor keys, you will see the "Setting keyclick to loud"
  440. information come up on the screen some time PRIOR to the keyclicks
  441. actually changing to loud.  This is because the remainder the macro
  442. only runs when the System Screen application has a chance to respond
  443. to the incoming sequence of keys (and since the System Screen is in
  444. background at this time, any keys typed into the foreground
  445. application will get processed at a higher priority - thereby
  446. delaying the conclusion of the macro playback).
  447.  
  448. A simple idea to fix this would be to rearrange the macro as follows:
  449.  
  450.     MACRO Set keyclick loud
  451.     KEY L
  452.     QUIET
  453.     CONTENTS
  454.     gSystem
  455.     627 8, 257, 257, 257, 108, 13
  456.     IKeyclick set to loud
  457.  
  458. The result is that the "I" command only gets acted on when the
  459. preceding sequence of keys has actually finished being processed.
  460.  
  461. However, if you try this change to the macro, you will find that no
  462. information message appears on the screen.  This is because
  463. information messages (created by "I" commands) are always displayed
  464. by the current "attached process".  In this case, the attached
  465. process is the System Screen.
  466.  
  467. To make this new macro work properly, you will need to insert an "f"
  468. command just before the "I" line.  Thus
  469.  
  470.     MACRO Set keyclick loud
  471.     KEY L
  472.     QUIET
  473.     CONTENTS
  474.     gSystem
  475.     627 8, 257, 257, 257, 108, 13
  476.     f
  477.     IKeyclick set to loud
  478.  
  479. The effect of the "f" command is to attach KMAC to the current
  480. foreground process.  All subsequent KMAC commands will be directed
  481. towards that process - or until such time as another command may
  482. cause another change in which process is the attached one.
  483.  
  484. For clarity, it should be emphasised that the notion of a process
  485. being in "foreground" is quite distinct from that of a process being
  486. "attached" to KMAC.  The foreground process is the one whose screen
  487. is shown, and which receives all standard keys as typed on the
  488. keyboard.  The attached process is the one which receives all KMAC
  489. commands.
  490.  
  491. Note also that all KMAC macros start of, by default, by attaching to
  492. the current foreground process.  If this is undesireable, put the
  493. keyword "BACKGROUND" in the header of the macro definition (in
  494. between the "MACRO" keyword and the "CONTENTS" keyword).
  495.  
  496. Upper-case and lower-case letter commands
  497. -----------------------------------------
  498. Note that the commands "F" and "f" are quite different: the "f"
  499. command causes KMAC to attach to the current foreground process,
  500. whereas the "F" command causes KMAC to move the current attached
  501. process into foreground.
  502.  
  503. Although there is no strict rule for which commands are represented
  504. by upper case letters and which by lower case letters, the following
  505. guiding principle generally applies: commands have upper case letters
  506. if they involve the active cooperation of the attached process,
  507. whereas they have lower case letters if they only cause changes
  508. within the KMAC process itself.
  509.  
  510. Thus the "g" command (the "go to" command) simply alters which process
  511. is the one KMAC is attached to.  By contrast, the "G" command (the
  512. "Ground state" command) involves setting Esc keypresses to the
  513. attached application, until such time as any dialogs, help screens,
  514. or menus showing have all been cancelled.
  515.  
  516. Again, the "I" command (the "Information message" command) requests
  517. the attached process to display an information message in the top
  518. left corner of its screen.  By contrast, the "i" command (the "image
  519. launcher" command) merely executes a specified image (usually .IMG)
  520. utility program (see later for examples).
  521.  
  522. Abbreviations are possible
  523. --------------------------
  524. In fact, in the header sections of .KMA files, only the first letters
  525. of keywords are significant, and the remainder of the first word on
  526. the line is always skipped.
  527.  
  528. This means that instead of typing eg 
  529.  
  530.     MACRO Set keyclick loud
  531.     KEY L
  532.     QUIET
  533.     CONTENTS
  534.     gSystem
  535.     ...
  536.  
  537. you could just type
  538.  
  539.     M Set keyclick loud
  540.     K L
  541.     Q
  542.     C
  543.     gSystem
  544.     ...
  545.  
  546. Requesting user confirmation during macros
  547. ------------------------------------------
  548. Try typing in the following macro definition (remember that you need
  549. to use an editor such as KMACED to edit macro definitions, and that
  550. you need to exit KMAC before you start editing, and then restart it
  551. after you have finished editing):
  552.  
  553.     MACRO Bring
  554.     Q
  555.     K B
  556.     C
  557.     QOkay to Bring?
  558.     xd0
  559.     L24
  560.  
  561. Restart KMAC, and go to the Agenda and highlight an appointment. 
  562. Next go to the Database and press Shift-Ctrl-B.
  563.  
  564. The effect of the "Q" command, as you will see, is to display a query
  565. dialog.  This can have either one or two lines of text - depending on
  566. whether a comma is found in the string after the "Q".  Thus
  567.  
  568.     QOkay to Bring?
  569.  
  570. results in a query dialog with only one line of text, whereas
  571.  
  572.     QOkay to Bring,(press 'N' to cancel)
  573.  
  574. results in a query dialog with two lines of text.  In either case,
  575. the dialog has a No/Yes pair of action buttons.
  576.  
  577. The way the macro tests the result of this dialog (ie whether the
  578. user chose 'Yes' or 'No') is by testing the value of the so-called
  579. "d-variable" ("d" for "decision"), at some later stage in the macro. 
  580. There are various methods of testing the d-variable.  In this case,
  581. the "x" command (the "eXit" command) is used.
  582.  
  583. The "x" command has various formats.  You can use "x" all by itself,
  584. to exit macro playback unconditionally.  Or you can follow the "x"
  585. with several different test criteria.  Here, the "xd" variant is used
  586. (see later for the other possibilities).  "xd0" means to exit macro
  587. playback if the d-variable has value 0 (or less).
  588.  
  589. The prior "Q" dialog sets the d-variable to 1 if the user chose
  590. 'Yes', and otherwise to 0.
  591.  
  592. Placing a "Q" command in a macro can avoid accidents if the user
  593. chooses the wrong macro hotkey by mistake.
  594.  
  595. A variant on the "Q" command is the "N" command (the "Notify"
  596. command).  This has exactly the same syntax, except that the No/Yes
  597. pair of action buttons is replaced by a single "Continue" action
  598. button.  Since there is no decision to be made in this case, the
  599. current value of the d-variable is not altered by the "Notify"
  600. dialog.  (As for "Q", the "N" command can specify either one or two
  601. lines of text.)
  602.  
  603. Note: the "L" command (the "Link paste" command) attempts to "Bring"
  604. up to the specified number of characters from the first paragraph of
  605. highlighted text in the application that is currently the "Link paste
  606. server".  (The terms "Bring" and "Link paste" are interchangeable.) 
  607. If the second parameter - 24 in the above example - is omitted, the
  608. maximum number of characters to bring is set to 128.  An error
  609. results if this value is specified as greater than 128.
  610.  
  611. Interrupting macro playback
  612. ---------------------------
  613. Note that you can always interrupt macro playback by pressing the
  614. Shift-Ctrl-Esc key combination.  This fact may be helpful if you have
  615. started macro playback in error.
  616.  
  617. The macro will be interrupted, by KMAC, at the earliest possible
  618. opportunity.  Occasionally, this may not be immediate - eg if the
  619. macro is inside a "P" ("pause") or "y" ("yield") command (see below
  620. for more about these commands).  Also, if the user presses
  621. Shift-Ctrl-Esc while the macro is waiting for the user to answer an
  622. "N" or "Q" dialog, the macro will be interrupted only after the
  623. dialog is answered.
  624.  
  625. Sending strings of keys - the "S" command
  626. -----------------------------------------
  627. When you are looking at a macro inside a .KMA file, you may have
  628. difficulty, at times, in discerning the exact meanings of all the
  629. different keys inside a command such as
  630.  
  631.     627 8, 257, 257, 257, 108, 13
  632.  
  633. For convenience, KMAC also supports the "S" command for sending
  634. sequences of keypresses to an application.  This sends a specified
  635. "string" of keys one at a time, where the keys are either
  636.  
  637.     standard printable keys
  638.     special "interpretable" keys (prefixed by an ^ character)
  639.     psion or shift-psion menu hot keys (prefixed by an @ character).
  640.  
  641. The "S" command results by default in keypreses with the modifiers
  642. set to zero, though this can be overridden by means of another use of
  643. the @ prefix character: @4 means to use Ctrl as the modifier for the
  644. next key in the sequence, and so on (see below for more details).
  645.  
  646. The following "S" command will have the same effect as the above
  647. sequence of raw keycodes:
  648.  
  649.     S@s^D^D^DQ^C
  650.  
  651. At first, this might not seem any clearer, but in time you may well
  652. come to appreciate the power of this command.
  653.  
  654. In this case:
  655.     @s means Psion-s (note that @S would mean Shift-Psion-S)
  656.     ^D means the Down key
  657.     Q is not preceded by either ^ or @, so it just means a Q key
  658.     ^C means the Enter key (C for "Confirm").
  659.  
  660. The full range of interpretable keys supported by the "S" command are
  661.  
  662.     Up, Down, Left, Right, Home, End, Tab, and Menu - all specified
  663. by their first letter (eg M for Menu, T for Tab)
  664.  
  665.     C for Return, X for Escape, P for PgUp, Q for PgDn
  666.  
  667.     ? for the current drive letter (A or I or B or ...), which can be
  668. useful in macros sending keys to drive selectors in dialogs (the
  669. current drive letter is from the drive KMAC was launched from)
  670.  
  671.     + for Diamond, - for Delete
  672.  
  673.     Y to Yield CPU until all other background and foreground
  674. processes finish all their pending activity
  675.  
  676.     0 to 9 to pause for 0 to 9 seconds (see below), and % to pause
  677. for half a second.
  678.  
  679. To send a literal ^ character, put ^^, and to send a literal @
  680. character, put @@.
  681.  
  682. Put @<digit> to force the modifiers for the following key in the
  683. stream to be <digit> (except that if the next key in the stream is of
  684. type @a or @A, the preceding @<digit> just gets ignored - and the
  685. modifiers are set to PSION and SHIFT-PSION in these two cases).  Note
  686. one complication here which is that the value of the PSION modifier
  687. is usually 8, but for these purposes it is changed to 1.  This is to
  688. allow @5 to specify modifiers CTRL-PSION, which would not be possible
  689. (using only a single digit) if the PSION modifier were 8 as usual.
  690.  
  691. Timing issues
  692. -------------
  693. Sooner or later a macro will fail to have to same effect when it is
  694. played back as it had when it was recorded.  There are several
  695. possible reasons for this and the next few sections in this document
  696. cover some of these.  One thing to watch out for, in particular, is
  697. the issue of *timing*, and the general solution to this kind of
  698. problem is to add in one or other kind of "P" ("pause") or "y"
  699. ("yield") commands into a macro.
  700.  
  701. When a macro is being recorded, other processes generally have a
  702. chance to run on the S3a (within the application and outside the
  703. application) at the same time as when keys are being pressed.  But
  704. during macro playback, by default the playback takes place at the
  705. highest priority - which may mean that the macro feeds an application
  706. keypresses before the application is ready to receive them.
  707.  
  708. For example, a macro that tabs out a file selector will in general
  709. need to insert a pause command before continuing to send keys to that
  710. file selector.  You'll find you need this if the file selector starts
  711. beeping at you during playback.  The reason here is that it can take
  712. the file selector some time to create its file list, but it remains
  713. responsive to keypresses in the meantime.  (This is to remain
  714. responsive to keys such as LEFT and RIGHT which will change the
  715. directory being scanned.)
  716.  
  717. The "P" command takes an optional parameter, which is how many tenths
  718. of a second playback should be suspended before continuing.  By
  719. default (ie if no parameter is given), the playback is just suspended
  720. until all other activity in the application has finished.  Note that
  721. in either case, the suspension takes place *within the attached
  722. application* (rather than inside KMAC itself).
  723.  
  724. Note that you can add pause statements inside an "S" command.  Thus
  725.  
  726.     S@m^T
  727.     P
  728.     256 4
  729.  
  730. can be shortened, effectively, to
  731.  
  732.     S@m^T^0@4^U
  733.  
  734. and likewise "P10" is equivalent to "S^1", and so on.
  735.  
  736. Pauses of longer than zero seconds can be particularly effective in
  737. pacing playbacks intended to demonstrate various aspects of some
  738. software (eg in point-of-sales demos).
  739.  
  740. An alternative to the "P" command is the "y" command, which has a
  741. rather different effect.  This pauses KMAC itself, by means of
  742. setting its process priority to one less than that standardly taken
  743. by background processes.  As a result, KMAC will only continue
  744. running when *all* foreground and background processes finish
  745. processing all events pending in them.  When this happens, the
  746. priority of KMAC is reset to what it was beforehand.
  747.  
  748. A sequence of macro commands such as
  749.  
  750.     S@m^T
  751.     y
  752.     256 4
  753.  
  754. can be rewritten as
  755.  
  756.     S@m^T^Y@4^U
  757.  
  758. A note on process priorities
  759. ----------------------------
  760. By default, KMAC runs at the rather high process priority of 0xa0. 
  761. This is higher than the priorities of any of the standard
  762. applications - higher even than Time, which runs at 0x90 (under the
  763. rationale that an alarm due to sound should always interrupt activity
  764. in other processes).
  765.  
  766. The reason for running KMAC at such a high priority is so that macro
  767. playback can be as quick as possible - without having to wait for the
  768. attached application to redraw itself unnecessarily between each two
  769. keypresses sent to it.
  770.  
  771. Working round bugs in system code exposed by KMAC macros
  772. --------------------------------------------------------
  773. Certain macros that you write may expose some shortcomings in the S3a
  774. system code.  Ordinarily, these shortcomings do not matter, since the
  775. system software is never normally exercised quite so intensively as
  776. during macro playback.  However, some of these problems may
  777. occasionally cause frustration during macro playback - and can even
  778. cause applications to "panic", with loss of data that has not yet
  779. been saved to file.
  780.  
  781. For this reason, you should always save your data before playing back
  782. a new keyboard macro, until you have confidence in that macro.
  783.  
  784. One example of a problem you can encounter is in a macro like the
  785. following:
  786.  
  787.     gData.dbf
  788.     F
  789.     S@m^T
  790.  
  791. The intention of this macro is to
  792.     "go to" the application editing the file "Data.dbf"
  793.     make this application foreground
  794.     press psion-m to display the "Merge" dialog
  795.     press Tab to tab out the file selector
  796.  
  797. However, if this macro is played back starting from an application
  798. *other* than the specified database, the database panics 73 shortly
  799. after being made foreground.  The root cause of this is when an
  800. application becomes foreground when a file selector is showing that
  801. was created when the application was effectively still in background
  802. (and when the file selector hasn't yet finished building its file
  803. list).
  804.  
  805. In this case, the fix is simple enough: insert a "P" command directly
  806. after the "F" command.  This pauses macro playback until all pending
  807. activity within the attached application has been processed.  In
  808. particular, the database gets a chance to process the foreground
  809. notification message from the Window Server, prior to going on to
  810. process the keypress messages that cause it to create the file
  811. selector.  (Bear in mind that applications process keys from macro
  812. playback at a higher priority than any other input from eg the Window
  813. Server.)
  814.  
  815. More generally, I try to avoid full-screen file selectors in macro
  816. playback.  I prefer to use Control-Tab to jump straight to the
  817. "Specify file list" dialog, and then Control-Enter to jump straight
  818. back to the dialog level, thereby avoiding the full-screen file
  819. selector altogether. 
  820.  
  821. Single stepping macros - the "s" command
  822. ----------------------------------------
  823. Inevitably, macros will go wrong for all kinds of reason.  To try to
  824. pin down where the blame lies, you can use the "s" command to put your
  825. macro into one of three different "single stepping" states.
  826.  
  827. By default, all macros operate inside "s0" - which has single
  828. stepping turned off, and thus macro playback proceeds at full speed.
  829.  
  830. But if the line "s1" is encountered in a macro, the macro will wait
  831. for the user to press Shift-Ctrl-Diamond before each subsequent line
  832. in the macro.  This state will continue until either the end of the
  833. macro is reached, or another "s" command is reached.  By using "s1"
  834. like this, you can carefully think through what each step in your
  835. macro is doing.
  836.  
  837. Occasionally, you may forget that KMAC is still waiting for a
  838. Shift-Ctrl-Diamond keypress before being able to do anything else. 
  839. But if this happens, and you try to do something else with KMAC, you
  840. will see a notifier explaining the situation.
  841.  
  842. As an alternative to "s1", you may find "s2" especially useful.  In
  843. addition to waiting for the user to press Shift-Ctrl-Diamond in
  844. between each step of the macro, this mode also displays a notifier
  845. containing the text of the line about to be played back, which the
  846. user has to acknowledge by pressing Esc, before the line is actually
  847. processed.
  848.  
  849. Bear in mind, however, that single stepping can alter the "timing"
  850. features of macros, and therefore can affect their performance.
  851.  
  852. Waiting for user synchronisation during macros
  853. ----------------------------------------------
  854. In some macros, you may wish to pause indefinitely between two lines
  855. of the macro - not for any reason of "debugging", but instead to
  856. allow the user to interact directly with the application before
  857. allowing the macro to continue.
  858.  
  859. This can be achieved by an "s1" command followed immediately
  860. afterwards by an "s0" command.  The macro pauses when it reaches
  861. "s1", and then waits for the user to press Shift-Ctrl-Diamond before
  862. proceeding.  In the meantime, the user can type any additional
  863. specific keys.
  864.  
  865. The single command "n" (the "nudge" command) can be used as an
  866. alternative to "s1" followed by "s0".  The effect is exactly the
  867. same.
  868.  
  869. Keyboard macros and Opl or Hwif applications
  870. --------------------------------------------
  871. Note that KMAC cannot interact with any application written in Opl or
  872. in Hwif.  You can only record or playback macros for applications
  873. written using the HWIM object-oriented system.  If you try to invoke
  874. KMAC with regard to an application not written using HWIM, KMAC will
  875. present an error notifier.
  876.  
  877. This is a fundamental limitation of Opl and Hwif applications and
  878. there is no prospect that a future version of KMAC for the S3a will
  879. remove this limitation.  For much the same reason, KMAC cannot
  880. operate on an S3 - only on an S3a.
  881.  
  882. One consequence of this is that some macros will fail, when you
  883. attempt to invoke them from an Opl or Hwif program.  Consider again
  884. the "Set keyclick loud" macro:
  885.  
  886.     MACRO Set keyclick loud
  887.     KEY L
  888.     QUIET
  889.     CONTENTS
  890.     gSystem
  891.     627 8, 257, 257, 257, 108, 13
  892.     f
  893.     IKeyclick set to loud
  894.  
  895. By default, this macro starts the same as all macros do, by
  896. attempting to attach to the current foreground process.  However, for
  897. this particular macro, this step is unnecessary.  Better, therefore,
  898. to add in the keyword "BACKGROUND" in the header of the macro:
  899.  
  900.     MACRO Set keyclick loud
  901.     KEY L
  902.     QUIET
  903.     BACKGROUND
  904.     CONTENTS
  905.     gSystem
  906.     627 8, 257, 257, 257, 108, 13
  907.     f
  908.     IKeyclick set to loud
  909.  
  910. This has the effect of letting the macro run at least as far as the
  911. "f" line before it fails.  It therefore succeeds in its main purpose,
  912. although it is unable to display an info message at the end to
  913. announce its success.
  914.  
  915. If you wished to avoid the final error message, you could use the "q"
  916. command (the "query attachable" command) to find out whether it is
  917. possible to attach to the current foreground process.  Like the "Q"
  918. command discussed earlier, this sets the "d-variable", that can be
  919. tested eg by a subsequent "x" command.  Thus the macro becomes
  920.  
  921.     MACRO Set keyclick loud
  922.     KEY L
  923.     QUIET
  924.     BACKGROUND
  925.     CONTENTS
  926.     gSystem
  927.     627 8, 257, 257, 257, 108, 13
  928.     q
  929.     xd0
  930.     f
  931.     IKeyclick set to loud
  932.  
  933. (q sets the d-variable to 1 if the foreground process is attachable,
  934. and otherwise to 0).  The macro only proceeds to its final two lines
  935. if the current foreground process is attachable.
  936.  
  937. Taking commands from additional .KMA files
  938. ------------------------------------------
  939. Several different KMAC commands allow commands to be read from an
  940. auxiliary .KMA file, instead of from the main one loaded into KMAC on
  941. startup.
  942.  
  943. In each case, the "script" file has the same basic format as the
  944. CONTENTS section of an individual macro definition.  For example, the
  945. contents of a file "Delrec.kma" could be the lines
  946.  
  947.     8
  948.     P
  949.     J2
  950.     x
  951.     SY
  952.     m0
  953.  
  954. (see later for the meanings of all the commands in this particular
  955. script file) - the same mixture of raw keycodes ("8" being the
  956. keycode for Delete) and alphabetic commands as could belong in the
  957. CONTENTS section of any macro definition.
  958.  
  959. One way of causing macro control to transfer to a specified script is
  960. by using the "l" (or "Launch script") command.  Thus the command
  961.  
  962.     lDelrec
  963.  
  964. will have the effect of launching the script file "Delrec.kma" from
  965. the same directory as the current top-level KMA file is in.  (Specify
  966. the full pathname and/or extension to look in a different place.)
  967.  
  968. Once control has been transferred to a script like this, it remains
  969. there until it is "returned", using the "r" command.  In the
  970. meantime, it is possible for the entire playback to be terminated,
  971. using the "x" ("exit") command.
  972.  
  973. In addition to the "l" command, there are two other commands that can
  974. cause a script file to be launched: the "d" (or "divert") command,
  975. and the "e" (or "on Error") command.
  976.  
  977. The "divert" command
  978. --------------------
  979. The "d" command attempts to divert control to a script whose name is
  980. formed from a specified string, together with up to one of the
  981. following "names":
  982.  
  983.    if "%d" is present in the specified string, this gets replaced
  984. by the current value of the d-variable
  985.  
  986.    if "%s" is present, this gets replaced by the "status name" (up to
  987. the extension) of the attached application
  988.  
  989.    if "%f" is present, this gets replaced by the "family name" (or
  990. "alias name") of the attached application
  991.  
  992.    if "%p" is present, this gets replaced by the "process name" of
  993. the attached application.
  994.  
  995. Eg "dA%f" will look for a script file "Aprog.kma" in the case of the
  996. attached process being the program editor, whereas "dA%p" will look
  997. for a script file "Aword.kma".  (On a technical note, the "status
  998. name" is taken from DatStatusNamePtr, the "family name" is taken from
  999. DatProcessNamePtr, and the "process name" is taken from
  1000. DatCommandPtr.  These three "names" appear in various different KMAC
  1001. commands.)
  1002.  
  1003. If the script filename specified by a "d" command does not exist,
  1004. macro playback simply passes onto the next line of the macro.
  1005.  
  1006. The "on error" command
  1007. ----------------------
  1008. The "e" command (the "on error" command) can be used to take
  1009. corrective action if an error arises in a particular line in a macro.
  1010. In case an error arises, control is diverted to the script specified
  1011. in the "e" command.
  1012.  
  1013. For example, the sequence of commands
  1014.  
  1015.     eStartDbf
  1016.     gLOC::M:\DAT\KMAC.DBF
  1017.     F
  1018.     614 8, 27, 9
  1019.     lDelrec
  1020.     C
  1021.  
  1022. has the following effect:
  1023.  
  1024. 1. The script name "StartDbf" is lodged as the current error-handler
  1025. 2. The full form of the "goto" command is used to try to go to the
  1026. application editing the specified full path name
  1027. 3. If such an application exists, the macro passes immediately onto
  1028. the next line in the main script - the "F" command
  1029. 4. Otherwise, control passes to the script file "StartDbf.kma"
  1030. instead, and only passes to the "F" command (if ever) when an "r"
  1031. command is encountered in "StartDbf.kma".
  1032.  
  1033. Some advantages of using script files
  1034. -------------------------------------
  1035. Some advantages of using script files should be pointed out:
  1036.  
  1037. 1. They cut down the amount of memory overhead required when running
  1038. KMAC.  Only the commands in the top-level script are loaded
  1039. permanently into memory.
  1040.  
  1041. 2. Macro details in scripts can be changed without having to exit and
  1042. restart KMAC before these changes become effective.
  1043.  
  1044. 3. Using the "divert" command, more than 26 different macros can, in
  1045. effect, be assigned hotkeys.  Thus the effect of Shift-Ctrl-A while
  1046. in the Program Editor might be quite different (on account of using
  1047. the "d" command) from in the Agenda.
  1048.  
  1049. 4. Scripts can play a very useful role in "error recovery" - as
  1050. illustrated above.
  1051.  
  1052. 5. Scripts can play a very useful role in other "test, jump, and
  1053. move" situations - as is discussed below.
  1054.  
  1055. Starting applications during macro playback
  1056. -------------------------------------------
  1057. In the above example, the script file "StartDbf.kma" has to arrange
  1058. for the Database application to be running and editing the file
  1059. "M:\DAT\Kmac.dbf".  This can be arranged by use of the two commands
  1060. "c" (set the "command line") and "p" (the "program start" command).
  1061.  
  1062. In fact the actual contents of "StartDbf.kma" would be as follows:
  1063.  
  1064.     cOData#.DBF#LOC::M:\DAT\KMAC.DBF#
  1065.     pROM::DATA.APP
  1066.  
  1067. For a full understanding of this use of the "c" command, you need to
  1068. understand about the format of command lines passed to applications
  1069. on the S3a.  Briefly, there are five portions to such a command line:
  1070.  
  1071. 1. The very first letter is either 'O' (to "Open" an existing file)
  1072. or 'C' (to "Create" a new file with a specified name)
  1073.  
  1074. 2. Immediately following this comes a zero-terminated string given
  1075. the "family name" to be used (note: case is sensitive here) - in fact
  1076. the operation of the KMAC "c" command turns all hash ('#') characters
  1077. into zeroes
  1078.  
  1079. 3. After the zero, and up to the next zero or up to the first
  1080. full-stop (whichever comes first) is the "alias info" to be used
  1081. (this is NULL in the above example)
  1082.  
  1083. 4. If the alias info was terminated by a full-stop, the text from the
  1084. full-stop to the next zero gives the "default extension" to be used
  1085. by the application
  1086.  
  1087. 5. Finally, the full path name of the file to be opened or created
  1088. must be passed (and it is important not to omit the final zero).
  1089.  
  1090. What the KMAC "c" command actually does is to store the given text,
  1091. so that subsequent commands (such as the "p" or "i" commands) can
  1092. access it.  As mentioned, all hash characters in the specified string
  1093. are converted into zeroes before the text is stored.
  1094.  
  1095. The KMAC "p" command attempts to launch the specified program name
  1096. (the "ROM::" specifies that the program is to be found in the ROM of
  1097. the S3a), using the command line stored by the previous "c" command. 
  1098. If successful, KMAC attaches to this application.
  1099.  
  1100. Ways of attaching to programs
  1101. -----------------------------
  1102. The "p" command (the "program start" command), just discussed, is one
  1103. method for attaching KMAC to a specified application.  Another
  1104. method, also discussed earlier, is the "g" command (the "go to"
  1105. command).
  1106.  
  1107. There are actually two forms of the "g" command - the "short form"
  1108. and the "long form".  The distinction is that the "long form" is used
  1109. whenever a colon or a backslash is found in the filename specified.
  1110.  
  1111. In the long form of the "go to" command, KMAC searches for a process
  1112. which has the given full pathname stored at its "DatUsedPathNamePtr". 
  1113. But in the short form, KMAC only searches for a process which has the
  1114. given short-form filename at its "DatStatusNamePtr".  Clearly, the
  1115. long form is more exact, but the short form will suffice in most
  1116. practical cases.  (Also, the long form cannot be used for
  1117. applications that are not file-based.)
  1118.  
  1119. Yet another way of attaching to a process is to use the "a" (or
  1120. "attach") command.  This works rather differently, treating the
  1121. specified string as a "process name identifier".  Examples of the use
  1122. of "a" would be "aSYS$SHLL.*" or "aWORD.*".  ("SYS$SHLL is the name
  1123. of the program which users see as the "System Screen".)
  1124.  
  1125. Conditional and unconditional exit and return commands
  1126. ------------------------------------------------------
  1127. Mention has already been made of the "r" ("return") and "x" ("exit")
  1128. commands.  Each of these exist in both unconditional and conditional
  1129. forms.  Thus the single letter on its own always causes a return or
  1130. an exit to take place.  However, either letter can be followed with
  1131. any of the following four sub-cases:
  1132.  
  1133.     d - means to return (or exit) if the current value of the
  1134. d-variable is less than or equal to the given number (usually used in
  1135. "xd0" or "rd0")
  1136.  
  1137.     p - means to return if the "process name" of the attached process
  1138. (read from DatCommandPtr) differs from the string given - eg "xpWORD"
  1139. would mean to exit playback unless the attached process was an
  1140. instance of the Word Processor
  1141.  
  1142.     f - means to return if the "family name" of the attached process
  1143. (read from DatProcessNamePtr) differs from the string given - eg
  1144. "xfPROG" would mean to exit playback unless the attached process was
  1145. actually the Program Editor
  1146.  
  1147.     s - means to return if the "status name" of the attached process
  1148. (read from DatStatusNamePtr) differs from the string given - eg
  1149. "xsTEST.OPL" would mean to exit playback unless the attached process
  1150. was editing a file called "TEST.OPL").
  1151.  
  1152. In all cases of the various "names" of the attached process, case is
  1153. not sensitive.  Thus "xfPROG" and "xfProg" would be identical.
  1154.  
  1155. Jumps and moves and tests during macro playback
  1156. -----------------------------------------------
  1157. The "d", "e", "r", and "x" commands already discussed give various
  1158. measures of control over what exactly happens during macro playback. 
  1159. This section introduces the very important "m", "j", and "J"
  1160. commands.
  1161.  
  1162. The "m" (or "move") command causes the focus of control to move
  1163. inside the current script (or top-level macro definition).  If no
  1164. additional parameter is given, playback moves past the next command,
  1165. skipping it altogether.  If an additional parameter is given that is
  1166. positive - eg "m3" - the specified number of steps are skipped. 
  1167. Finally, the command "m0" has the special meaning of rewinding to the
  1168. beginning of the current script (or if control is currently in the
  1169. top level macro definition, to the beginning of that definition) and
  1170. proceeding forwards again from there.
  1171.  
  1172. The "j" (or "jump depending on number of dialogs shown") command
  1173. allows the macro to count the number of dialogs shown on the screen
  1174. of the attached process, and to move past a specified number of steps
  1175. depending on this number.  The general syntax of the "j" command is
  1176. "jm,n", where <n> defaults to 1 and can be omitted, and (also like
  1177. the case of the "m" command) can be given as 0, in which case macro
  1178. control can rewind to the beginning of the current script or
  1179. top-level macro definition.  If <m> is positive, the jump is taken if
  1180. the number of dialogs shown exceeds m, whereas if <m> is negative,
  1181. the jump is taken if the number of dialogs shown is less than (-m).
  1182.  
  1183. The "J" command (or "Jump on general condition" command) works very
  1184. similar to the "j" command, except that the set of conditions tested
  1185. is very general.
  1186.  
  1187. For example, the "J2" command in the "Delrec" script given earlier
  1188. has the effect of skipping over the next line in the script (actually
  1189. an "exit" command) if a dialog is showing on the screen - this is
  1190. because the "general status info" of the attached application
  1191. contains the value 2 if a dialog is showing.  (See the following
  1192. section for more details.)
  1193.  
  1194. The "J2" command in "Delrec" could in fact be replaced by "j0" in
  1195. this case.
  1196.  
  1197. The precise syntax of the "J" command is "Jm,n" where <n> has exactly
  1198. the same meaning as for "j" (and for "m").  The jump is taken, for
  1199. positive <m>, if the "status info" of the attached process, ANDed
  1200. with m, is non-zero.  If <m> is negative, the jump is taken if the
  1201. corresponding AND value is zero.
  1202.  
  1203. General status info for the attached process
  1204. --------------------------------------------
  1205. Bits are set in the "general status info" of the attached process as
  1206. follows:
  1207.  
  1208.     1 is set if a menu is showing
  1209.     2 is set if a dialog is showing
  1210.     4 is set if the application is "locked" (ie would report as
  1211. "busy" in the System Screen)
  1212.     8 is set if the application has a keyboard filter active
  1213.     16 is set if the application has a non-negative i/o semaphore
  1214. value (meaning that there is pending activity in the application)
  1215.     32 is set if the application has called am_start more than once
  1216. (meaning that it is in some kind of modal state).
  1217.  
  1218. A full explanation of all these terms is beyond the scope of the
  1219. present documentation.  (The various bits all indicate some kind of
  1220. pending activity that it might be better not to interrupt.)
  1221.  
  1222. Synchronisation issues with regard to tests
  1223. -------------------------------------------
  1224. Note that the above "Delrec" script contains the line "P" prior to
  1225. making the "J" test.  This is important.  Otherwise the wrong result
  1226. would be obtained.  The point is that although the effect of the
  1227. previous line in the macro - sending the Delete key - would be to
  1228. bring up a "Delete?" query dialog in due course, the "J" test could
  1229. be carried out before that dialog was actually created.
  1230.  
  1231. The KMAC expression evaluator
  1232. -----------------------------
  1233. One more aspect of the "names" feature of KMAC deserves explicit
  1234. mention.  This is used in the "E" (or "Expression evaluate")
  1235. command.  Despite its name, this command has no scope for evaluating
  1236. numerical expressions.  Instead, the allowed contents of the
  1237. expression to be evaluated are the familiar "names" identifiers "%p",
  1238. "%f", and "%s".  It turns out that this can be very useful.
  1239.  
  1240. The string evaluated in this way is sent to the attached process as a
  1241. string of keys.
  1242.  
  1243. For example, the command "E%s.txt" would send the string of keys
  1244. "Notes.txt" when the file being edited is "Notes.wrd", and would send
  1245. the string of keys "Memo.txt" when the file being edited is
  1246. "Memo.wrd".  This could be exactly the right thing to type into a
  1247. filename editor line of a "Save as" dialog in an application.
  1248.  
  1249. Transferring control to Opl programs
  1250. ------------------------------------
  1251. Although there is a wide range of control features available to KMAC
  1252. programs, some macros may demand additional data manipulation or
  1253. tests to be carried out.  For this reason, KMAC supports the notion
  1254. of launching an Opl program, which can then use many of the features
  1255. of KMAC in its own right.
  1256.  
  1257. The way this works is that the functionality of KMAC has actually
  1258. been split into two different pieces of code.  Script file handling
  1259. and background key capture, etc, is handled by code in KMAC.APP
  1260. itself, but most of the logic for implementing playback is located in
  1261. LPC.DYL.  The logic in LPC.DYL has been designed in such a way as to
  1262. make it accessible from an Opl program as well.
  1263.  
  1264. For further details of Opl programs that can use LPC, see the text
  1265. file OPLLPC.TXT.
  1266.  
  1267. Miscellaneous KMAC commands
  1268. ---------------------------
  1269. For a summary of all the possible alphabetic commands recognised by
  1270. KMAC, see the database file KMAC.DBF.
  1271.  
  1272. A few features not mentioned so far can be pointed out:
  1273.  
  1274. There are "k" ("kill"), "t" ("terminate"), and "C" ("closedown")
  1275. commands, which provide various means of exiting the current attached
  1276. application.
  1277.  
  1278. There is an "i" command, to start a specified utility application,
  1279. without any attempt to attach to it.  (This uses, for its command
  1280. line, anything set up by a prior "c" command.)
  1281.  
  1282. There is an "A" command, to cause the attached process to display
  1283. "alloc heap information", which can be very useful during program
  1284. development (to monitor possible memory leakage).
  1285.  
  1286. There is a "B" command, to send the attached program into background. 
  1287.  
  1288. There is a "v" command, to remember the PID of the current attached
  1289. process, and a "u" ("use") command, to attach back to the process
  1290. whose PID was remembered earlier.
  1291.  
  1292. There is an "H" ("Hook DYL") command, to cause the attached process
  1293. to hook a specified DYL (see elsewhere for information on how to
  1294. write such a DYL, and for examples of the use of this command). There
  1295. is also an "h" command, to cause KMAC itself to hook a specified DYL.
  1296.  
  1297. Finally, there is an "o" command, to start a specified Opl program -
  1298. eg "o\OPO\TKMACLIB.OPO" - and a "w" command, to wait for the
  1299. completion of the Opl program last launched using an "o" command (or
  1300. for the completion of the image program last launched using an "i"
  1301. command).
  1302.  
  1303. Review of the macros in EG.KMA
  1304. ------------------------------
  1305. See the text file EGKMA.TXT for a discussion of the example macros
  1306. contained in the file EG.KMA.
  1307.  
  1308. These notes prepared by
  1309. -----------------------
  1310. David Wood, Psion Product Development, 25th April 1994.
  1311.