Keys Action (Android Objects)

Applies to TestComplete 15.69, last modified on November 13, 2024
This method is available in legacy mobile tests that work with devices connected to the local computer. To learn how to simulate user actions in newer cloud-compatible mobile tests, see the Simulating user actions in tests section.

Description

The Keys action selects (focuses) an object and types text into it. You can combine text with special keys like Ctrl or Backspace.

Declaration

TestObj.Keys(Keys)

TestObj A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section
Keys [in]    Required    String    
Result None

Applies To

All Android objects

View Mode

This method is available in the Object Browser panel and in other panels and dialogs in both Basic and Advanced view modes.

Parameters

The method has the following parameter:

Keys

The text to type. It can include special keys from the following table:

Code Simulated Key
^ Ctrl
! Shift
~ Alt
^^ ^
!! !
~~ ~
[[ [
[Apps] App switch key
[BS] Backspace
[Clear] Clear
[Del] Delete
[Down] Down
[End] End
[Enter] Enter
[Esc] Back
[F1] F1
[F2] F2
[F3] F3
[F4] F4
[F5] F5
[F6] F6
[F7] F7
[F8] F8
[F9] F9
[F10] F10
[F11] F11
[F12] F12
Code Simulated Key
[Home] Home
[Ins] Insert
[Left] Left
[NumAsterisk] Num * (* on the numeric keyboard)
[NumMinus] Num - (- on the numeric keyboard)
[NumPlus] Num + (+ on the numeric keyboard)
[NumSlash] Num / (/ on the numeric keyboard)
[PageDown] Page Down
[PageUp] Page Up
[Pause] Pause
[Right] Right
[Tab] Tab
[Up] Up
[Win] Home key
[Pnnn] Pauses typing for nnn milliseconds.
All constants (F1, PageDown, X, P, etc.) are case-sensitive.

Result Value

None.

Remarks

To input local symbols in Android applications, the Keys action 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 a 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 (Legacy).

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

function CtrlPlusA()
{
  Mobile.SetCurrent("MyDevice")
  var p = Mobile.Device().Process("smartbear.example.orders");
  var Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name");
  Edit.Keys("^A")
}

Python

def CtrlPlusA():
  Mobile.SetCurrent("MyDevice") 
  p = Mobile.Device().Process("smartbear.example.orders")
  Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name")
  Edit.Keys("^A")

VBScript

Sub CtrlPlusA
  Dim p, Edit
  Mobile.SetCurrent("MyDevice")
  Set p = Mobile.Device.Process("smartbear.example.orders")
  Set Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name")
  Edit.Keys("^A")
End Sub

DelphiScript

function CtrlPlusA;
var p, Edit;
begin
  Mobile.SetCurrent('MyDevice');
  p := Mobile.Device.Process('smartbear.example.orders');
  Edit := p.RootLayout('').ScrollView('NO_ID').EditText('cust_name');
  Edit.Keys('^A');
end;

C++Script, C#Script

function CtrlPlusA()
{
  Mobile["SetCurrent"]("MyDevice")
  var p = Mobile["Device"]["Process"]("smartbear.example.orders");
  var Edit = p["RootLayout"]("")["ScrollView"]("NO_ID")["EditText"]("cust_name");
  Edit["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

function CtrlAndA()
{
  Mobile.SetCurrent("MyDevice")
  var p = Mobile.Device().Process("smartbear.example.orders");
  var Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name");
  Edit.Keys("^")
  Edit.Keys("A")
}

Python

def CtrlAndA():
  Mobile.SetCurrent("MyDevice") 
  p = Mobile.Device().Process("smartbear.example.orders")
  Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name")
  Edit.Keys("^")
  Edit.Keys("A")

VBScript

Sub CtrlAndA
  Dim p, Edit
  Mobile.SetCurrent("MyDevice")
  Set p = Mobile.Device.Process("smartbear.example.orders")
  Set Edit = p.RootLayout("").ScrollView("NO_ID").EditText("cust_name")
  Edit.Keys("^")
  Edit.Keys("A")
End Sub

DelphiScript

function CtrlAndA;
var p, Edit;
begin
  Mobile.SetCurrent('MyDevice');
  p := Mobile.Device.Process('smartbear.example.orders');
  Edit := p.RootLayout('').ScrollView('NO_ID').EditText('cust_name');
  Edit.Keys('^');
  Edit.Keys('A');
end;

C++Script, C#Script

function CtrlAndA()
{
  Mobile["SetCurrent"]("MyDevice")
  var p = Mobile["Device"]["Process"]("smartbear.example.orders");
  var Edit = p["RootLayout"]("")["ScrollView"]("NO_ID")["EditText"]("cust_name");
  Edit["Keys"]("^")
  Edit["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.

See Also

Testing Mobile Applications
Simulating Text Input on Android Devices (Legacy)
Simulating Local Symbol Input (Legacy)
SetText Action (Mobile Controls)

Highlight search results