Description
Types text in the active application and object on the connected Android device. You can use special keys like Ctrl and Backspace.
Declaration
AndroidDeviceObj.Keys(Keys)
AndroidDeviceObj | An expression, variable or parameter that specifies a reference to an AndroidDevice object | |||
Keys | [in] | Required | String | |
Result | None |
Applies To
The method is applied to the following object:
Parameters
The method has the following parameter:
Keys
The text to type. It can include special keys from the following table:
|
|
All constants (F1 , PageDown , X , P , etc.) are case-sensitive. |
Result Value
None.
Remarks
This method is asynchronous. This means that TestComplete continues running the test, no matter whether it has finished or not. For information on how it may affect testing on Android devices, see Possible Issues.
To input local symbols on Android devices, the Keys
method uses the TestComplete Android Agent keyboard. If TestComplete cannot use the Agent keyboard (for instance, if it is disabled or the on-screen keyboard must not be shown), it inputs text by using the virtual keyboard device. The set of key declarations, the key character map file contains, is different on different devices. In most cases, it includes alphanumeric and special characters. For more information on inputting local symbols, see Simulating Local Symbol Input.
Shift codes (^, ~ and !) in the Keys parameter do not press Ctrl, Alt or Shift. Instead, the next key in the string will be pressed under the indicated shift conditions. That is, the shift codes affect the first non-shift key that follows them in the Keys string. For instance, the following code presses Ctrl+A (this key combination selects the whole text in the control):
JavaScript, JScript
Mobile.Device().Keys("^A");
Python
Mobile.Device().Keys("^A")
VBScript
Mobile.Device.Keys("^A")
DelphiScript
Mobile.Device.Keys('^A');
C++Script, C#Script
Mobile["Device"]["Keys"]("^A");
To separate shift-key presses from combined key presses like those above, use two consecutive calls of the Keys
method. For example, the following code first presses Ctrl and then A (this operation does not select the whole text, since the key presses are separated). Another way to achieve this effect is to use the [Release]
constant (more below).
JavaScript, JScript
Mobile.Device().Keys("^");
Mobile.Device().Keys("A");
Python
Mobile.Device().Keys("^")
Mobile.Device().Keys("A")
VBScript
Mobile.Device.Keys("^")
Mobile.Device.Keys("A")
DelphiScript
Mobile.Device.Keys('^');
Mobile.Device.Keys('A');
C++Script, C#Script
Mobile["Device"]["Keys"]("^");
Mobile["Device"]["Keys"]("A");
To simulate multi-key shortcuts (two or more keys pressed at the same time), use [Hold]
to press and hold a key, [ReleaseLast]
to release the last pressed key, and [Release]
to release all the pressed keys. For example:
Code | Key Combination | Description |
---|---|---|
[Hold]^f[ReleaseLast]U |
Ctrl+f then Ctrl+U |
Press and hold Ctrl, press and release f , press and release U, release Ctrl. |
[Hold]!^fU[Release] [Hold]!^fU |
Shift+Ctrl+f then Shift+Ctrl+U |
Press and hold Shift and Ctrl, press and release f , press and release U, release Shift and Ctrl. |
[Hold], [Release] and [ReleaseLast] affect only the state of the Ctrl, Shift and Alt keys. |
Example
This example shows how to use the Keys
method to enter text on an Android device:
JavaScript, JScript
function Test()
{
// Specify the current device
Mobile.SetCurrent("MyDevice");
// Launch the tested application
…
// Simulate user actions
…
Mobile.Device().Keys("iddqd");
…
}
Python
def Test():
# Specify the current device
Mobile.SetCurrent("MyDevice")
# Launch the tested application
# ...
# Simulate user actions
# ...
Mobile.Device().Keys("iddqd")
# ...
VBScript
Sub Test
' Specify the current device
Call Mobile.SetCurrent("MyDevice")
' Launch the tested application
…
' Simulate user actions
…
Call Mobile.Device.Keys("iddqd")
…
End Sub
DelphiScript
procedure Test;
begin
// Specify the current device
Mobile.SetCurrent('MyDevice');
// Launch the tested application
…
// Simulate user actions
…
Mobile.Device.Keys('iddqd');
…
end;
C++Script, C#Script
function Test()
{
// Specify the current device
Mobile["SetCurrent"]("MyDevice");
// Launch the tested application
…
// Simulate user actions
…
Mobile["Device"]["Keys"]("iddqd");
…
}
See Also
AndroidDevice Object
iOSDevice Object
Testing Android Applications
Testing iOS Applications