This shows you the differences between two versions of the page.
sample_code:extra_keys [2014/09/21 10:19] 81.174.242.106 created |
sample_code:extra_keys [2014/12/07 04:56] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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 | ||
- | |||
- | <code javascript keys.js> | ||
- | //keys.js | ||
- | var gEdt; | ||
- | //Called when application is started. | ||
- | function OnStart(){ | ||
- | //Create a layout with objects vertically centered. | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | //Create a text edit and add it to layout. | ||
- | edt = app.CreateTextEdit( " | ||
- | edt.SetTextSize( 32 ); | ||
- | lay.AddChild( edt ); | ||
- | //Create a checkbox for overstrike mode | ||
- | chkOvertype = app.CreateCheckBox(" | ||
- | lay.AddChild(chkOvertype); | ||
- | //create a horizontal layout for special characters | ||
- | lay_keys = app.CreateLayout(" | ||
- | btns = [] | ||
- | var ks = ' | ||
- | for(i=0; 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, | ||
- | } else{ | ||
- | gEdt.ReplaceText(s, | ||
- | gEdt.SetCursorPos(pos + s.length); | ||
- | } | ||
- | } | ||
- | </ |