Actions can set shortcut keys that perform actions when pressed. In this example, the form is submitted when the F2 key is pressed.
To define a shortcut key, use the keypress option of an item. The keypress option is created by the Viewer when the form is opened, and is updated when the user presses a key. The change in value is an event that can be captured by the toggle function in a action.
The keypress event occurs in the item that has the focus when the user presses a key. If the key that is pressed is not a valid key for the item, then the current page and the global page can also respond to the keypress event. For example, if the user presses the "A"
key while in a text field, the keypress is captured only by the field. But if the F2 key is pressed, the event is captured by the field, by the current page, and by the global page. This is because the F2 key is not a valid input character for a text field. This characteristic is used to capture a keypress at the page or global page level.
Keys such as the Caps Lock, Tab, and arrow keys are not captured.
This example shows how to use a custom action in the current page to submit a form when the F2 key is pressed. It works by setting the activated option of the submit button to "on"
when the toggle function detects a change in the keypress option of the current page.
To create a shortcut key for a submit button:
- Select the Submit Form Button from the Palette and drop it into the form.
The Properties Dialog opens. For this example, no changes to the Properties window are required. Click OK to close the Properties window.
- Click on a blank area of the form to remove focus from the button, then right-click and click Action Editor -> Custom Action Editor.
The Action Editor window opens.
- In the Option box, type custom:keyF2.
- Click Quick Start and from the menu, click Keyboard Shortcut.
The Action Editor displays the Keyboard Shortcut template, and highlights the word "shortcutKey".
- Replace the word "shortcutKey" by typing F2.
- Press the Tab key until the word "action" is highlighted.
- Click Function.
The Action Editor | Function window opens.
- In the Function panel, click Utility -> set.
The set menu opens and the reference parameter is highlighted.
- Click Form Item.
The Action Editor minimizes so the form is visible.
- Click the Submit button and from the Option menu, click activated.
- Click OK on each of the open windows.
The completed action should appear as follows:
toggle(global.keypress, '', 'F2') == '1' ? set('PAGE1.SUBMIT1.activated', ''): ''
When the form is used, pressing the F2 key submits the form.
Parent topic: Action Editor