Microsoft Knowledge Base

How to Set Up a Hotkey to Stop a Microsoft Test Script

Last reviewed: April 25, 1995
Article ID: Q126673
The information in this article applies to:
  • Microsoft Test for Windows, versions 2.0 and 3.0

SUMMARY

You can stop a Microsoft Test script from running if you press CTRL+BREAK keys. This requires that the focus be on Microsoft Test's main window when you press those keys to stop the script. When Microsoft Test is running the focus may be on the application's window in which case this method of stopping the script will not work.

MORE INFORMATION

You can use the predefined KEYTRAP in your Test script to stop your script from running even if the focus is not on Microsoft Test's main window by pressing a hot key.

With Microsoft Test you can build event traps in your Test scripts. Event trapping gives your script the ability to trap and respond to a wide range of external events such as keystrokes. Microsoft Test has some predefined Traps which you can use in your scripts . You can use KeyTrap in conjunction with SetHotKey to stop a script.

The key trap, KeyTrap, is designed to let you trap keys with or without accompanying shift states.

To trap a key, use the following TRAP statement:

Microsoft Test 3.0 Syntax

TRAP KeyTrap FROM "T3TRAP16.DLL" ALIAS "KeyTrap" 'or "T3Trap32.DLL"

    event-handler-statements
END TRAP

Microsoft Test 2.0 Syntax

TRAP KeyTrap FROM "TESTTRAP.DLL" ALIAS "KeyTrap"

    event-handler-statements
END TRAP

Sample Code

The following code stops a script from runing if you press the keys "CTRL+C".

'$INCLUDE: 'Declares'
' DEMONSTRATES HOW TO USE THE KEYTRAP TO ABORT A SCRIPT

'SET UP TRAP ROUTINE
'You can modify the following line if you are running it using Test 2.0

'$IFDEF Win32
TRAP KeyTrap FROM "T3Trap32.DLL" ALIAS "KeyTrap" 'or T3Trap32.DLL
'$ELSE
TRAP KeyTrap FROM "T3Trap16.DLL" ALIAS "KeyTrap" 'or T3Trap32.DLL
'$ENDIF
     Beep
     STATUSBOX "HOT KEY PRESSED, ABORTING SCRIPT @" + Time$
     SLEEP 4
     END    'ABORT SCRIPT
END TRAP

'MAIN SCRIPT

SetHotKey ASC("C"),  1   'TRAP Ctrl+c
Beep
STATUSBOX "Press CTRL+C to see this script ABORT" Sleep 'SLEEP FOREVER END

REFERENCES

Microsoft Test 3.0 User's Guide, "Event Trapping" section of Chapter 6, Advanced Programming Techniques, pages 186-189.

Microsoft Test 2.0 User's Guide, "Event Trapping" section of Chapter 6, Advanced Programming Techniques, pages 171-174.

KeyTrap topic of Microsoft Test Help file.


Additional reference words: keytrap 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: kbnocat


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 25, 1995
©1997 Microsoft Corporation. All rights reserved. Legal Notices.