EXAMPLE OF LOOPING FOR KEYSTROKE V4.02
======================================

This keydef contains an example 'loop'.

ie it performs the same action over and over again until
you stop it by holding down the ESCAPE key or until it
finishes.

This example is designed to load one drawfile at a time into
!Draw and resave the file and then procede onto the next drawfile
in the filer directory you pick.

To see it in action, first 'clear all' Keystrokes in !Keystroke
and drag and drop the Keydef file on the Keystroke icon on the icon bar.

Then pop up a directory containing one or more drawfiles.

Place your pointer within this directory and press ALT-Q

You should see !Draw load a drawfile, perform a save without
altering the contents of the file and quit again.

It will do this with each Drawfile within the directory
and then stop.





HOW IT WORKS
============

Page 1 on Keystroke - ALT Q
---------------------------
"<Keystroke$Lib>.FileList4 <Pointer$Text> drawfile"
 
It uses the Keystroke Library function 'FileList4' to get a list
of files which are only Drawfiles.

'<Pointer$Text>' will contain at time of execution the path of the
filer window the Pointer is hovering over.

'drawfile' is used by FileList4 to indicate to it that you are only
interested in knowing about drawfiles!

Detail on what Filelist4 does can be found in the Keystroke Library
List file.
Basically it set variables numbered from 1 to whatever, each of which
holds the full pathname to each drawfile.

ie
KS$dir1 could be : ADFS::Harddisc4.$.clipart.Phone
KS$dir2 could be : ADFS::Harddisc4.$.clipart.Pen
KS$dir3 could be : ADFS::Harddisc4.$.clipart.Book
etc.

Also the number of files it found is stored in 'KSno'.



Page 2 on Keystroke - ALT Q
----------------------------

This simply sets a variable called 'KSloop' to a value of 1
(we use this later to indicate we want to look at the first file in the
directory containing a drawfile).

Page 3 on Keystroke - ALT Q
----------------------------
IF "<Ksno>" >"0" Then Keystroke Loop

This line means if the variable 'KSno' (which is set by FileList4 to the number
of files it found) is greater than 0 then goto a Keystroke action called 'loop'.

So if no drawfile were found then KSno would be set to 0 and so nothing more
would happen.


'loop'
Page 1 on Keystroke - ALT -SHIFT - Q
-------------------------------------
SetEval KSobject KS$dir<KSloop>

We need this line to convert the KS$dir?, KS$Dir?, etc. to
a single variable.

So on the first pass, KSloop is equal to '1' so KS$Dir1 is read
and the full pathname is passed to KSobject.

Page 2 on Keystroke - ALT -SHIFT - Q
-------------------------------------
Resources:$.Apps.!Draw <KSObject>

This loads !Draw with a drawfile, the pathname is taken from the
variable KSobject (you need to place it wrapped in <> as otherwise it
just thinks 'KSobject' is a filename!

So !Draw loads with the Drawfile in it!

Page 3 on Keystroke - ALT -SHIFT - Q
-------------------------------------
Since !Draw is now loaded and should have the 'input focus' automatically
a simple '\F3\|M' sends !Draw a Function Key F3 followed by a Return key
command and this is all that is required to cause the file in Draw to be
resaved.


Obviously it is important to realise that we've assumed that !Draw does
get the input focus (as it does in RISC OS 3.5+) if the keypresses we are
trying to send it are going to work.
If it didn't then perhaps an extra action might have had to be performed
prior to this to ensure this.
We suggest that if you're planning to copy this example with another
application and it doesn't automatically get the input focus then
perhaps a manual icon click on the background of the application would
ensure that it has the input focus first.    

Page 4 on Keystroke - ALT -SHIFT - Q
-------------------------------------
<Keystroke$Lib>.QuitTASK Draw

This Keystroke library function forces Draw to quit.
Much easier to do than a menu selection to click on the Quit option!

Page 5 on Keystroke - ALT -SHIFT - Q
-------------------------------------
Seteval KSloop <KSloop> + 1

The contents of KSloop are incremented by one.
So the next time around the loop we'll be looking at the next file on
the 'list'.

Page 6 on Keystroke - ALT -SHIFT - Q
-------------------------------------
IF <KSloop> <= KSno then Keystroke loop

This ensures that if the contents of KSloop are less than or equal to
the number of Drawfiles then the command 'Keystroke loop' is performed.
Which will make Keystroke go back to Page 1 on ALT-SHIFT-Q as this is
labelled 'loop' otherwise the sequence will finish!




There are many times where you may wish to perform looping,
Perhaps you wish to process the same command over and over again to
a collection of files. Or perhaps you wish to monitor a window or
application and act upon it when it is finished or when it starts.

The above example should be a good building block which you can start with.



end.


 Quantum Software 1998
email support@quantumsoft.co.uk if you have any questions about this.


 



