Microsoft KB Archive/126673

= 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