How to Use Hot Keys in Visual FoxPro

This article was previously published under Q128752
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
Like FoxPro 2.x, Visual FoxPro provides support for access keys in objects.In addition to the standard types of access keys for objects, Visual FoxProalso now supports access keys on Label controls.
MORE INFORMATION
Access keys in Visual FoxPro work the same as they did in earlier releasesof FoxPro. An access key combination is defined by including the controlcharacters 'back slash-left angle bracket' (\<) within the text caption ofthe selected object.

You may be familiar with the use of access keys for an object such as aFoxPro 2.x push button. Visual FoxPro has extended this ability to includethe Label control as well. In FoxPro 2.x, this functionality was difficultto achieve and required additional work on the part of the programmer.

In Visual FoxPro, access keys are added to label controls in the samemanner as you would add one to any other object, such as a push button. Itis important to keep the following key points in mind when using thisfunctionality:
  • The Label control has a tab index value located under the 'Other' tab of the Label Properties sheet.
  • Labels that are assigned an access key value will activate the nextobject in the tab index order. If you have a form that has a label controlwith a tab index value of 2 on it and an access key value of the letter'a' , when the user presses ALT+A, the object which has tab index value 3will receive focus. In most cases, this would ordinarily be an object suchas a combo box or text box.

Step-by-Step Example

In the ORDENTRY screen of the TASTRADE project, located in theSAMPLES\MAINSAMP subdirectory of Visual FoxPro, the customer field has anaccess key value of C. The tab index order for the Label control is 1. Tabindex 2 is the cboCustomer_Id field, so when ALT+C is pressed, focus movesto the cboCustomer_Id field. The following procedure shows how to examinethis screen:
  1. Open or switch to Microsoft Visual FoxPro.
  2. From the File menu, choose Open. This invokes the Open dialog box. Under the 'List Files of Type' list box, select Project.
  3. Select the MAINSAMP directory as found in \VFP\SAMPLES\MAINSAMP.
  4. Choose the TASTRADE project and click OK.
  5. In the Project Manager, click the plus sign (+) next to the word Documents.
  6. Click the plus (+) sign next to the word Forms.
  7. From the list of forms, choose Ordentry.
NOTE: You should also be aware that access keys can be assigned to numbersas well as to text. The following Label control caption is activated bypressing ALT+3:
  Label1.Caption = 'Number \<3'				
The following Visual FoxPro objects support the use of access keys:
CheckBox
CommandButton
Label
OptionButton
Page
For objects like CommandGroups and PageFrame pages, you must select theappropriate object in the group. For example, in a PageFrame, to add anaccess key to a caption on a page, you must select the Page 1 object fromthe PageFrame. Note that Header objects in a grid don't support accesskeys.

If a user presses an access key combination for an object on a currentlyinactive form that is part of a FormSet, the inactive form will beactivated. Pressing hot keys that are independent and separate from anyFormSet will NOT activate the independent form.

Access keys on menus have not changed in Visual FoxPro. Although you candefine an access key in a menu using by using the control character (\<)sequence, access keys must still be assigned to menu pads and bars by usingthe shortcut option. For the purposes of this document, shortcut key andaccess key are used interchangeably. As before, when a menu pad has anaccess key defined, you will not see any indicator that an access key hasbeen assigned unless you specifically add the access or shortcut keysequence to the pad name.

Bars under a pad do not have to have the access key sequence assigned tothe pad name. When a shortcut has been defined for a bar as it has been forthe bar named 'A menu bar' below, Visual FoxPro will list the access keycombination next to the pad name.
Mymenu  A menu bar ALT+A				
The order of precedence of menus and access keys has also not changed inVisual FoxPro. When two or more pads share the same access key combination,such as two pads both with a shortcut of ALT+Q, focus moves to the firstpad by default.

When a bar in a submenu has the same shortcut key as a menu pad, focusstill moves to the menu pad by default.

If you do define a shortcut key for a menu bar, you don't have to have anyshortcut key text. Removing the key text will result in a cleaner menulook. You can then clue the user to the access key by putting the controlkey sequence (\<) in front of the letter which defines the access orshortcut key.

NOTE: You can also define a number hot key in a menu.
VFoxWin Labels Hotkeys hot keys Forms
Properties

Article ID: 128752 - Last Review: 02/24/2014 08:19:39 - Revision: 1.2

  • Microsoft Visual FoxPro 3.0 Standard Edition
  • kbnosurvey kbarchive KB128752
Feedback