Send Keys
Send Keys start out as a PowerHome formula. This formula may be as simple as a sequence of keystrokes to be sent to the current window surrounded by single or double quotes so that the formula will evaluate properly. After the formula goes through variable substitution and evaluation, the result is passed to the Send Keys interpreter. The interpreter will then parse the result and simulate keystrokes.
To simulate someone pressing the ‘A’ key, the Send Keys formula would be the letter ‘a’ in lower case surrounded by single or double quotes. This string would be passed to the variable substitution routine where it would return unchanged. Next the formula evaluator will evaluate the formula and return the lower case ‘a’ without the surrounding quotes. The Send Keys interpreter would then create a Windows message telling the currently active application that the ‘a’ key was pressed. If you wanted to simulate someone pressing the shift key and the ‘A’ key, the command would be the letter ‘A’ in upper case surrounded by single or double quotes. This is the technique used for sending the standard typeable letters, numbers and special characters. If a key sequence does not have a standard sequence such as the tab key, you would use the special character syntax of ‘{tab}’. The curly braces denote a special character sequence. To simulate an alt + tab key combination, the syntax is ‘{alt+tab}’. Notice there are no spaces in this sequence. Having a space in a Send Keys sequence will simulate the space key being pressed. Also note that all the letters are lower case. This is important. Upper case letters in a special character sequence are only used in certain situations. The + symbol is used to separate items in a special character sequence. To simulate a function key such as F1, the syntax is ‘{F1}’. Note that the F is capitalized. This is the only time capitalization should be used in a special character sequence. The special character sequences available for Send Keys are listed below:
{shift}
{ctrl}
{alt}
{backspace}
{tab}
{enter}
{pause}
{capslock}
{esc}
{pageup}
{pagedown}
{end}
{home}
{leftarrow}
{rightarrow}
{uparrow}
{downarrow}
{printscreen}
{insert}
{delete}
{multiply}
{plus}
{minus}
{point}
{divide}
{numlock}
{scrolllock}
To simulate the numbers on the numpad keys such as the 1 key, use the syntax ‘{numpad+1}’. In the above example where we wanted to simulate the shift and ‘A’ key being pressed, we merely had to enter a capital ‘A’. We could also use the syntax ‘{shift+a}’ to accomplish the same. If you want to simulate a key sequence such as the control key, the shift key and the ‘A’ key, your syntax would be either ‘{shift+ctrl+a}’ or ‘{ctrl+shift+a}’. Remember, when building Send Keys formulas, do not separate special character sequences or groups of characters by spaces unless you want the space key to be pressed. To simulate a sequence of keys pressed one after the other, string the appropriate Send Keys syntax together one after another. Control A followed by the letter b followed by the enter key followed by the F1 key followed by an alt + tab sequence would be entered into a Send Keys formula as: ‘{ctrl+a}b{enter}{F1}{alt+tab}’. A ‘{}’ sequence (curly braces with nothing in between) has no effect and is ignored.
Remember that all Send Keys are first a formula. You can achieve a dynamic Send Keys sequence by having this formula evaluate to a sequence of keystrokes that will then be passed to the Send Keys interpreter.
NOTE: Case is extremely important when working with Send Keys commands. If you are not careful concerning case, your Send Keys will not be interpreted properly.