Back

DisableKeys

JS Py
Hello World

DisableKeys prevents the default behavior of several hard, soft or keyboard keys.

app.DisableKeys( keyList )

This way you can apply a custom action for them using SetOnKey.

You can find the complete list of keycodes on the Android Developer Page

Example - Surprise

var prev;

function OnStart()
{
    app.DisableKeys( "VOLUME_DOWN,VOLUME_UP" );

    lay = app.CreateLayout( "Linear", "FillX" );
    lay.SetPadding( 0, .85 );
    lay.Hide();

    img = app.CreateImage( "/Sys/Img/Hello.png", -1, .3 );
    lay.AddChild( img );

    app.AddLayout( lay );

    app.ShowPopup( "Press the volume keys!" );
    app.SetOnKey( OnKey );
}

function OnKey(action, name, code, extra)
{
    if( action != prev ) {
        if( action == "Down" ) lay.Animate( "SlideFromBottom", null, 300 );
        if( action == "Up" ) lay.Animate( "SlideToBottom" , null, 300 );
    }
    prev = action;
}
from native import app

prev

def OnStart():
    global lay
    app.DisableKeys( "VOLUME_DOWN,VOLUME_UP" )

    lay = app.CreateLayout( "Linear", "FillX" )
    lay.SetPadding( 0, .85 )
    lay.Hide()

    img = app.CreateImage( "/Sys/Img/Hello.png", -1, .3 )
    lay.AddChild( img )

    app.AddLayout( lay )

    app.ShowPopup( "Press the volume keys!" )
    app.SetOnKey( OnKey )

def OnKey(action, name, code, extra):
    if action != prev:
        if action == "Down":
            lay.Animate( "SlideFromBottom", None, 300 )
        if action == "Up":
            lay.Animate( "SlideToBottom" , None, 300 )
    prev = action
    Copy     Copy All       Run      
String: comma “,” separated: “VOLUME_DOWN”, “VOLUME_UP”, “FORWARD”, “BACK”, “MENU”, “ENTER”, “...”