This section includes two examples that use a mapped user event. For more user event examples, see “Communicating between a window and a user object”.
Situation You have several SingleLineEdit controls in a window and want the Enter key to behave like the Tab key. For example, you might want users to tab to the next SingleLineEdit when they press Enter.
Using the KeyDown function You cannot use the KeyDown PowerScript function to obtain a key code value entered by a user on a Windows CE platform.
Solution Define a user event for the first SingleLineEdit. Give the event any name you want, such as ue_CheckKey. Map the event to the event ID pbm_keydown. Write a script for the user event that tests for the key that was pressed on the Soft Input Panel (SIP) or peripheral keyboard. If Enter was pressed, set the focus to the SingleLineEdit that you want the user to go to.
For example, in the script for the user event for sle_1, you could code:
// Script for user event ue_CheckKey, // which is mapped to pbm_keydown. IF Key=KeyEnter! THEN // Go to sle_2 if sle_2.SetFocus( ) // Enter pressed. END IF
Situation You have a DataWindow control with a column that uses the RadioButton edit style and you want to allow users to scroll through the RadioButtons when they press Down Arrow or Up Arrow. (Normally, pressing Down Arrow or Up Arrow scrolls to the next or preceding row.)
Solution Declare a user event for the DataWindow control that maps to the event ID pbm_dwnkey and write a script like the following for it. (dwn stands for DataWindow notification.)
// Script is in a user event for a DataWindow control. // It is mapped to pbm_dwnkey. If user is in column // number 2, which uses the RadioButton edit style, and // presses DownArrow, the cursor moves to the next item // in the RadioButton list instead of going to the next // row in the DataWindow, which is the default behavior. // Pressing UpArrow moves to the preceding RadioButton. // // Note that the CHOOSE CASE below tests for data // values, not display values, for the RadioButtons.
int colnum = 2 // Column number long rownum rownum = dw_1.GetRow( ) // Current row IF This.GetColumn( ) = colnum THEN
CHOOSE CASE key CASE KeyDownArrow! CHOOSE CASE dw_1.GetItemString(rownum, colnum) CASE "a" // First value in RB This.SetItem(rownum, colnum,"b") // Next CASE "b" // Second value in RB This.SetItem(rownum, colnum,"c") // Next CASE "c" // Last value in RB This.SetItem(rownum, colnum,"a") // First END CHOOSE
CASE KeyUpArrow! CHOOSE CASE dw_1.GetItemString(rownum, colnum) CASE "a" // First value in RB This.SetItem(rownum, colnum,"c") // Last CASE "b" // Second value in RB This.SetItem(rownum, colnum,"a") // First CASE "c" // First value in RB This.SetItem(rownum, colnum,"b") // Previous END CHOOSE
END CHOOSE
END IF
return(1)