Keyboard Macros

Contents of Article


Introduction

Creating a macro using the Record function

Keyboard recording and Power Typing

Case Study: Implementing bookmarks

Case Study: Making editing easier on laptops


Introduction


SPFLite keyboard support allows you to create keyboard macros.  


Note that Keyboard Macros and Command Macros are completely different facilities.  Refer to Command Macro Support for more information.


A keyboard macro is a predefined series of keystrokes that are 'played back' when a specific key is pressed.  You can create this series of keyboard entries manually, as described in Customizing a Single Key, by typing each primitive function name, text, line command etc. from left to right in the appropriate text box.


For macros with only a few entries, this is certainly feasible.  For longer macros, the best approach may be to use the keyboard recording facility.  To do this, you must first know what the macro recording key is mapped to, or define it if necessary.


Note that the keyboard recording facility is not ‘magic'.  You will see that the end result of recording a macro is a text string in a key mapping definition entry, one that you could have typed yourself ‘the hard way'.  The benefit of keyboard recording is that you can define a macro by concentrating on the actual keystrokes you use, rather than the syntax of the various entries described above.


If you have not redefined it, the default for the keyboard (Record) function is the Scroll Lock key.  You are free to assign the (Record) function to any key you wish, as described above.  For laptop keyboards, you may need to hold the Fn key to access the Scroll Lock key.  


It may be best to not initially change the definition of the (Record) function, so as not to confuse yourself while reading this documentation.


Creating a macro using the Record function


To record a keyboard macro, follow the following steps:



Your macro is now ready to use.  


You should test your macro after defining it, to make sure it does what you intended.  Sometimes macros recorded as keystrokes this way are a little tricky to enter correctly on the first try, especially if they are long and complicated.  It might take a few attempts to get every keystroke just right.  If you find that a correction to a recorded macro is necessary, you can rerecord it by going through all those steps again. However, if it's just a minor flaw, you can simply edit the text definition of the macro that you pasted in.  That may be much easier than re-recording it.


Be aware that with Keyboard Recording, everything you type will be recorded.  That includes Backspace if you type something wrong and correct it.  What this really means is, unless you plan on editing your keyboard definition later, if you make a mistake you will need to start over.


Keyboard recording and Power Typing


Keyboard Recording is allowed during Power Typing.  However, since the status indicator is already showing .PowerType., the usual  message of .KB Recording. will not appear.  However, keyboard recording proceeds as usual.  When you press the key mapped to (Record), which by default is the Scroll Lock key, you will see the SPFLite KeyMap dialog will appear.  When you exit from KeyMap, Power Typing continues in effect.  You can immediately use any keys you have added or changed in KeyMap in your resumed Power Typing session.


Case Study: Implementing bookmarks


A number of Windows text editors have a bookmark capability, in which you can set several “marks” in various places in your file, and then go back and successively find them.  Here is an SPFLite implementation of such a capability, using tags as the representation of bookmarks.  (Not SPFLite bookmarks, a term used interchangeably with labels, but a more generalized kind of bookmark that can exist in multiple places.)


First, we arbitrarily choose a tag name to represent a bookmark; tag :M is selected.  See Working with Line Tags for more information on using tags.


Next, document the keys and the functions they will perform, which will be based on F2.  (In IBM ISPF, F2 is commonly assigned to the 3270 SPLIT-screen command, a function that is not implemented in SPFLite.  So, F2 may be a good choice as an available key to use.)  


We also want to keep the current cursor position when toggling bookmarks, so the toggle operation will be 'wrapped' in functions to save and restore the cursor. This example shows the use of SaveCursor and RestoreCursor functions.



Finally, set the mapping of key F2 accordingly, and allow the keys to auto-repeat:



User Lines provide an alternative to tags for implementing bookmarks.  Here is a possible implementation:



Case Study: Making editing easier on laptops


Many laptops have keys like Insert and Delete in unconventional and hard-to-reach places on the keyboard, and they can be tiring to use, whereas the arrow keys are usually easy to reach.  SPFLite key mapping can be used to provide an alternative for these hard-to-use keys.


First, document the features we wish to make available.  The functions Insert, Delete and Backspace are to be made available using the Ctrl-arrow keys.  


Since Delete has the effect of “pulling” a line over to the left by one column, we also want to provide a “push” function by allowing a single blank to be inserted.  It will be necessary to force the insert mode on, regardless of what it was before.  So, an ordinary toggle-insert-mode command won't work for this.  We also want to retain the cursor position after inserting a blank, to mirror how deletion of one character works.  To do that, we need to generate a Left-Arrow cursor movement afterwards.


Besides, if we wanted to insert characters and have the cursor ‘travel' we could always just use an ordinary Insert key and then hold down the spacebar.


We also want the insert mode restored to what it used to be, and not just always turn it off, so this example shows the use of RestoreInsert instead of ResetInsert.


The functions to be provided are:



Finally, set the mapping of these keys, and allow the keys to auto-repeat (which is useful, since the arrow keys naturally auto-repeat):




Created with the Personal Edition of HelpNDoc: Free EPub and documentation generator