Extra keys

This code snippet offers an extra line of keys to make some extra keys easier to get at.

It uses new features added in v1.09 beta, so will not work on release version 1.05

keys.js
//keys.js
var gEdt;
//Called when application is started.
function OnStart()
{
  //Create a layout with objects vertically centered.
  lay = app.CreateLayout("linear", "Vcenter,FillXY");
 
  //Create a text edit and add it to layout.
  edt = app.CreateTextEdit("Hello");
  edt.SetTextSize(32);
  lay.AddChild(edt);
  //Create a checkbox for overstrike mode
  chkOvertype = app.CreateCheckBox("Overtype");
  lay.AddChild(chkOvertype);
  //create a horizontal layout for special characters
  lay_keys = app.CreateLayout("linear", "Horizontal,FillY");
  btns = []
  var ks = '{}[]();#"' + "'"
  for (i = 0; i < ks.length; i++)
  {
    var ch = ks.charAt(i);
    btn = app.CreateButton(ch);
    btn.SetOnTouch(btn_OnTouch);
    lay_keys.AddChild(btn);
    btns.push(btn);
  }
  lay.AddChild(lay_keys);
 
  //Add layout to app.    
  app.AddLayout(lay);
  gEdt = edt;
}
 
function btn_OnTouch()
{
  var s = this.GetText();
  var pos = gEdt.GetCursorPos();
  var theEnd = gEdt.GetText().length;
  if (!chkOvertype.GetChecked())
  {
    gEdt.InsertText(s, pos);
  }
  else
  {
    gEdt.ReplaceText(s, pos, Math.min(pos + s.length, theEnd));
    gEdt.SetCursorPos(pos + s.length);
  }
}