![]() |
![]() |
Forms Recipe: Access Keys for Text Items
by Peter Koletzke
In forms that require heavy data entry, users find it easier to use the keyboard for many operations. When you design forms in this category, you need to consider how the user can use the keyboard to navigate from one item to another and to activate buttons. It is easier to move the cursor by pressing keys when your hands are on the keyboard than by reaching for, moving, and clicking the mouse. Your forms can be used more efficiently if you take this into consideration.
Forms implements the Windows concept of access keys that allow the user to move the cursor to an object by pressing a key combination. For example, if you press Alt-A, the Action pull-down menu will be activated. The menu access keys (also called hot-keys or shortcut keys) are familiar to any Windows user who prefers the keyboard to the mouse.
Forms extends the concept of menu access keys to other objects and allows you to define an access key for radio group buttons, buttons, and check boxes. There is no access key concept, however, for other items such as text items, list items, and image items. There is a technique you can use to supply access key functionality for those objects so you can make your forms "Alt-key accessible." This article describes this technique in the format of a "recipe" so you can create a home-baked version of the solution.
Defining an Access Key
Access keys are easy to define for the supported objects. The property list for radio group buttons, command buttons and check boxes includes a property called "Access Key" in the Functional group, as shown in Figure 1. You just type a single letter, number, or character as a value for this property. When the form runs, the user can press this character with the Alt key to make the cursor move to and activate the item.

Figure 1: Access Key property
You can use the characters A–Z in lower- or uppercase; the Alt- keypress will work with either. In other words, character access keys are case-insensitive. Some other characters also work; for example, you can define an access key of a single quote and one for a double quote. Although these two symbols are normally on the same key, the Alt-’ and Alt-" combinations will act as two separate keypresses. Therefore, you could have two buttons activated using the same key—one using a Shift keypress and one without. There are some other eccentricities, so if you use something other than a letter character, test the effect with and without the Shift key.
If there is a menu item access key defined the same as a button access key, the menu item will take precedence. Menu access keys are the first uppercase letter in the item label or the first letter after an ampersand. They display as an underlined character in the name of the item. For example, the menu item label "Action" has an underlined "A" and is activated with Alt-A. The menu item with a label of "E&dit" has an underlined "d" and is activated with Alt-d.
While running the form, the access key moves the cursor to the item and activates the item as in the following radio group.

Activating the item has a different effect depending on the object type. Basically, whatever would happen when the user clicks the object with the mouse cursor will happen when the access key is pressed: the menu item will be selected; the button will be pressed (and the WHEN-BUTTON-PRESSED trigger fired); a radio button will select its value; and a check box will toggle from checked to unchecked or unchecked to checked. Although you can define an access key for the radio group item (that contains the radio buttons), it has no effect.
If the item’s label includes the access key letter, the character in the label will be underlined when the form is run (although not in the Layout Editor), as shown in the illustration above. If the character is not in the label, the access key will work anyway, but the user will not know which key to press. The underline is a standard convention that indicates the access key.
Note
Another rule with access keys is that the item must be displayed (the Visible property set to "Yes") and assigned to a content or stacked canvas that is showing at the time the access key is pressed. If the object is on a toolbar canvas, the access key will work if the toolbar canvas is attached to the current window (not the MDI window).
Recipe for the Text Item Access Key
The problem is that access keys are not available for text items and you might want to allow the user to press a key combination to navigate directly to an item. This would be useful on a canvas that contains a large number of items, only some of which are required. Instead of pressing the Tab key to move from one item to the next, the user can press an access key.
Since text items do not have an access key property, the secret to this technique is to create a button (called an access key button) in the same block for each item that requires the access key. The button has Height and Width properties of zero and Visible property of "Yes" so that the access key will work but you will not see the button. WHEN-BUTTON-PRESSED trigger code automatically transfers the cursor to the text item with a similar name.
Preparation
As usual, a library procedure does the work. The main preparation is to write
this simple procedure. The procedure assumes that the button has the same name
as the item that the cursor is moving to, but with a _PB suffix. Therefore, the
ENAME item would use a ENAME_PB button as its access key button. The procedure
just determines the name of the button that was activated and moves the cursor
to the item of the same name without the _PB suffix. The procedure (as excerpted
from the F_ITEM library package) follows:
PROCEDURE access_key IS
v_button VARCHAR2(80) := :system.trigger_item;
v_go_item VARCHAR2(61) := substr(v_button, 1,
length(v_button) - 3);
BEGIN
IF NOT id_null(find_item(v_go_item))
THEN
go_item(v_go_item);
ELSE
message('Error: ACCESS_KEY failed to move to item called ' ||
v_go_item||'. Notify Technical Support.');
raise form_trigger_failure;
END IF;
END;
The other preparation step is to create the block with the text items you want to access with keypresses.
Ingredients
The main ingredients are the text items you want to assign access keys to and the procedure. You also need to create a WHEN-BUTTON-PRESSED trigger on the block level with the following code:
f_item.access_key;
This code will fire when any button in the block is clicked (or activated with an access key). If there are other buttons in the block, you need to add a conditional statement to check the suffix as follows:
IF substr(:system.trigger_item, -3) = '_PB' THEN f_item.access_key ELSE -- the code to handle other buttons END IF;
Tip
When creating a trigger for a button, using the Object Navigator, an LOV will be displayed with the list of potential triggers for that item. If you use the self-reducing feature of LOVs, you will be able to select a specific trigger more quickly than by scrolling to find the name. For example, click the Create button to display the triggers’ LOV after selecting the Triggers node under the form module. When the LOV displays, you can press the keys wnf to reduce the list to the WHEN-NEW-FORM-INSTANCE trigger. While the number of keys required to reduce the list varies with the trigger name, in time, you will learn these shortcut keys and be able to select a trigger name quickly. Also, be sure to check the SmartTriggers list (from the right-click menu) for the most commonly used triggers for a specific object type.
Steps
The following steps explain how to create an access key button for a single text item called ENAME that you want to move to using an Alt-n keypress.
Once you create an access key button with the proper settings, you can place it in the object library so you can subclass the main properties whenever you need to create another button. The Access Key and Canvas properties will be specific to the form, so you do not need to specify those for the object library version of the button.
Then, add boilerplate text to the canvas with the letter that you will underline. Select the text and click on the Underline button in the Layout Editor toolbar. The letter will be underlined as follows:

The only task left is to move the underlined character on top of the normal character. Select the text and use the arrow keys on the keyboard to position it. You may find it useful to zoom in to see the placement more easily. The result will be an underlined letter as follows:

Other Ideas
You can use this access key technique to have an access key display another canvas. To do this, add an access key button called EMP_CANVAS_PB to the first canvas. Then add a nonbase table item on EMP_CANVAS with 0 height and 0 width. The access key for the CANVAS2_PB button will then move the cursor to that text item on the EMP_CANVAS. If the user will interact with an item on the second canvas, you can just name the button with the name of that item and a _PB suffix.
Another way to make this system more flexible (to move to any block and any canvas) is to store the name of the item you are navigating to in the Label property of the access key button. For example, the ENAME_PB button would contain the Label property value "EMP.ENAME". You would change the code in the ACCESS_KEY procedure to:
go_item(get_item_property(name_in('SYSTEM.TRIGGER_ITEM', LABEL));
In this case, the names of the access key buttons do not have to be anything special.
About the Author
Peter Koletzke is a practitioner and self-proclaimed evangelist for Oracle Designer and Developer. He is a Consulting Manager and Principal Instructor for Millennia Vision Corporation (MVC), of Redwood Shores, CA. He is also a member of the Board of Directors of the International Oracle Users Group — Americas, a frequent contributor to national and international Oracle newsletters and users group conferences, and co-author, with Dr. Paul Dorsey, of two Oracle Press books: the Oracle Designer Handbook, Second Edition, (1998), and Oracle Developer Advanced Forms and Reports (1999) which was a basis for this paper. http://ourworld.compuserve.com/homepages/Peter_Koletzke
MVC is a new breed of business consulting firm dedicated to improving its clients' business performance and position in the expanding e-business economy. MVC's unique, integrated approach enables companies to align their people, processes, and technologies in support of their business strategy. Global leaders in a wide variety of industries rely on MVC's proven methodologies, knowledge products, professional expertise and technical depth to extend their existing business models and seize new opportunities. Sample files for this paper are available at the MVC web site: http://www.mvsn.com.