Send Key – Function 3
This function sends one or more keystrokes (up to a maximum of 255) to the connected Host session. The keystrokes appear to the session as if they are entered by a user. The keystrokes can include host function keys and AID keys.
Prerequisite function
Connect Presentation Space (function 1)
Function call
WinHLLAPI(SENDKEY,lpbyString,lpwLength,lpwReturnnCode)
Call parameter
Parameter Description
Data String String of keystrokes, maximum of 255 bytes (including host function key codes).
Data Length Length of Data String in bytes. This parameter is overridden if in EOT mode.
Return code
Code Description
WHLLOK The keystrokes were sent successfully.
WHLLNOTCONNECTED Your Windows HLLAPI application is currently not connected to a Host session.
WHLLPARAMETERERROR The function call contains an invalid parameter.
WHLLPSBUSY The session is busy; all of the keystrokes could not be sent.
WHLLINHIBITED Input to the session is inhibited; keystrokes were rejected or invalid host function key codes were sent. All of the keystrokes could not be sent.
WHLLSYSERROR The function failed due to a system error.
Remarks
You cannot send keystrokes to the Host session when the keyboard is locked or busy (input inhibited). You can check the keyboard status with Wait (function 4). It is also your responsibility to treat input-protected or numeric-only Host fields appropriately.
This function is affected by five session options specified by Set Session Parameters (function 9): AUTORESET/NORESET, STRLEN/STREOT, EOT=c, and ESC=c.
You can increase the performance of the Send Key function by setting the session option NORESET. If this session option is set to AUTORESET, a reset code is always added to the beginning of the keystroke string, resetting all states that can be reset (except input-inhibited states). The added reset code bytes are not deducted from the Data String length of 255.
By default, the length of the Data String parameter must be specified by the Data Length parameter. Optionally, you can implicitly define the Data Length parameter by using the EOT delimiter character, which is specified with Set Session Parameters (function 9).
Note
Better character transfer performance is achieved with Copy String To Field (function 33) or Copy String To Presentation Space (function 15). However, only this function (Send Key) can send the host function keys.
This function can be used to send host function keys (including AID keys) to the Host by using special codes. These codes consist of an Escape character (default is “@,” the “at” sign) and a mnemonic code that corresponds to the supported host functions. The desired host function key codes are included as part of the Data String parameters. The Escape character can be changed with the session option ESC=c. See Set Session Parameters (function 9) for details.
When the Data String contains AID keys, the string includes characters up to, and including, the first AID key encountered. The segment string and segment length are set internally to the proper values as the segment is sent to the Host. Because some Host applications process AID keys differently, some keystrokes in a subsequent segment could be lost. It is therefore required that you do not create a Data String containing more than one AID key.
The characters that make up the host function key codes are part of the Data String and make up its total length. This means that you must be careful when using host function key codes to not exceed the maximum of 255 characters in the Data String. For example, if you need to send a string that contains the Enter key (code @E), then the two bytes for the Enter code must be included in the Data Length parameter.
The following table lists the host function keys and their corresponding codes. Please note that if a character is used in the code, the case of the character is important.
Meaning Mnemonic 3270 5250
@ @@   X
Alt @A X  
Alternate cursor @$ X X
Attention @A@Q X X
Backspace @< X X
Backtab (Left tab) @B X X
Clear @C X X
Cmd function key @A@Y   X
Cursor down @V   X
Cursor left @L   X
Cursor right @Z   X
Cursor select @A@J   X
Cursor up @U X X
Delete @D X X
Dup @S@x X X
End @q   X
Enter @E X X
Erase EOF @F X X
Erase input @A@F X X
Field exit @A@E   X
Field mark @S@y X X
Field - @A@-   X
Field + @A@+   X
Help @H   X
Hexadecimal @A@X   X
Home @0 (zero) X X
Insert @1 X7 X
Insert toggle @A@I   X
Host print @P   X
Left tab (Back tab) @B X X
New line @N X X
Page up @u   X
Page down @v   X
Print (PC) @A@t   X
Record backspace @A@<   X
Reset @R X X
Right tab (Tab) @T X X
Shirt @S X  
Sys request @A@H X X
Tab (Right tab) @T X X
Test @A@C   X
PA1 @x X  
PA2 @y X  
PA3 @z X  
PA4 @+ X  
PA5 @% X  
PA6 @& X  
PA7 @' X  
PA8 @( X  
PA9 @) X  
PA10 @* X  
PF1/F1 @1 X X
PF2/F2 @2 X X
PF3/F3 @3 X X
PF4/F4 @4 X X
PF5/F5 @5 X X
PF6/F6 @6 X X
PF7/F7 @7 X X
PF8/F8 @8 X X
PF9/F9 @9 X X
PF10/F10 @a X X
PF11/F11 @b X X
PF12/F12 @c X X
PF13 @d X X
PF14 @e X X
PF15 @f X X
PF16 @g X X
PF17 @h X X
PF18 @i X X
PF19 @j X X
PF20 @k X X
PF21 @l X X
PF22 @m X X
PF23 @n X X
PF24 @o X X
Note
If you want to use the “at” sign (@) in the Data String, you must use the two-byte code “@@”.