Microsoft KB Archive/81221

= Microsoft Knowledge Base =

Test Must Use &quot;DoKeys {126}&quot; to Send Literal Tilde Character
Last reviewed: October 19, 1994

Article ID: Q81221

The information in this article applies to:

- Microsoft Test for Windows, version 1.0

SYMPTOMS
DoKeys &quot;{~}&quot; does not work as expected, and contrary to what is explained in the Test online Help, will result in an ENTER keystroke (carriage return) being sent to the active window, not a literal tilde.

RESOLUTION
To send a literal tilde character (~) using DoKeys or QueKeys, you need to enter the following:

DoKeys &quot;{126}&quot;

STATUS
Microsoft has confirmed this to be a bug in Microsoft Test version 1.0 for Windows. This bug was corrected in Microsoft Test version 2.0 for Windows.

MORE INFORMATION
DoKeys carries out the same action as calling QueKeys and QueFlush, and can be used in a Test script to simulate keystrokes. The tilde character is a special character normally used by DoKeys/QueKeys to represent the ENTER key; therefore, Chapter 10 of the &quot;Microsoft Test for Windows: User's Guide&quot; recommends putting the tilde character inside braces to send this character to the active window. However, placing brackets around a tilde character incorrectly results in an ENTER keystroke being sent to the active window.

The following steps reproduce the problem of the DoKeys sending an Enter keystroke instead of a tilde even though the tilde character is enclosed in curly braces as recommended.

Steps to Reproduce Problem
 Launch the Test Driver application by double-clicking its icon in Program Manager.  In a new test script, type the following code to start the Windows NOTEPAD.EXE program and send it keys. '$define testevnt '$include 'mstest.inc' 

run &quot;notepad.exe&quot;,nowait DoKeys &quot;{126}&quot; DoKeys &quot;{enter}&quot; DoKeys &quot;126 in brackets will print as a tilde &quot; DoKeys &quot;{~}&quot; DoKeys &quot;this text should be preceded by a tilde&quot; DoKeys &quot;{enter}&quot; DoKeys &quot;but instead it is on a new line as if enter had been typed&quot;


 * 1) From the Run menu, choose Start to run the script.

The output in Notepad will appear as follows:

~  126 in brackets will print as a tilde this text should be preceded by a tilde but instead it is on a new line as if enter had been typed Note: The tilde did not print, but instead acted as a carriage return in Notepad, making the text of the next DoKeys start on the next line.

This behavior is incorrect. Using braces {} around the other special characters (plus sign [+], caret [^], and percent sign [%]) works as expected, and produces the literal characters instead of the special DoKeys/QueKeys interpretation.