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:
SUMMARYYou 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 INFORMATIONYou 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 SyntaxTRAP KeyTrap FROM "T3TRAP16.DLL" ALIAS "KeyTrap" 'or "T3Trap32.DLL" event-handler-statementsEND TRAP
Microsoft Test 2.0 SyntaxTRAP KeyTrap FROM "TESTTRAP.DLL" ALIAS "KeyTrap" event-handler-statementsEND TRAP
Sample CodeThe 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 Win32TRAP KeyTrap FROM "T3Trap32.DLL" ALIAS "KeyTrap" 'or T3Trap32.DLL '$ELSETRAP 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
REFERENCESMicrosoft 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
©1997 Microsoft Corporation. All rights reserved. Legal Notices. |