Back

SimulateKey

JS Py
Hello World

Simulates a key event on an app object.

app.SimulateKey( obj, keyName, modifiers?, pause? )

You can find the complete list of key names on the Android Developer Page

Example - Infinite Monkey

function OnStart()
{
    lay = app.CreateLayout( "linear", "VCenter,FillXY" );
    edt = app.CreateTextEdit( "", 0.8, 0.3, "nokeyboard" );
    lay.AddChild( edt );
    app.AddLayout( lay );

    app.Animate( SimulateKey, 2 );
}

function SimulateKey()
{
    var ran = 65 + Math.floor(Math.random() * 26);
    var char = String.fromCharCode( ran );
    app.SimulateKey( edt, char );
}
from native import app
import math
import random

def OnStart():
    global edt
    lay = app.CreateLayout( "linear", "VCenter,FillXY" )
    edt = app.CreateTextEdit( "", 0.8, 0.3, "nokeyboard" )
    lay.AddChild( edt )
    app.AddLayout( lay )

    app.Animate( SimulateKey, 2 )

def SimulateKey(time, dtime):
    ran = 65 + math.floor(random.random() * 26)
    char = chr( ran )
    app.SimulateKey( edt, char )
    Copy     Copy All       Run      
app object
Number
String
String: “META_META_ON”, “META_RIGHT_ON”, “NUM_LOCK_ON”, “SCROLL_LOCK_ON”, “SHIFT_LEFT_ON”, “SHIFT_MASK”, “SHIFT_ON”, “SHIFT_RIGHT_ON”, “SYM_ON”