Rocket Uniface User Forum

 View Only

User Keys explained – what options do I have for handling Keyboard Shortcuts (updated)

By Kathy Larson posted 06-27-2023 17:46

  

By Jasper de Keijzer

Introduction 

When creating or managing client-server applications, it is frequently beneficial to employ different keyboard shortcuts to increase efficiency. Although keyboard shortcuts are typically used with menus, this article investigates the utilization of keyboard shortcuts in a Uniface Windows application that doesn't have menus. The objective of this new approach is to enable end users or system administrators to modify keyboard shortcuts in the usys.ini file without accessing the application's source code. This functionality was already available for menu accelerators but was absent for Forms that do not have a menu. 

Accelerators 

Accelerators are keyboard combinations linked to specific menu items. These combinations can be defined in the usys.ini file. In the [accelerators] section, you can connect a key combination with a menu item in a form component, like the example below: 

[accelerators] 

Fileopen=Ctrl+O 

By defining "Fileopen" in the menu editor, Uniface automatically adds "Ctrl+O" to the menu text and registers it as an accelerator in Windows. Pressing Ctrl+O activates the menu item without displaying the characters in the current field. The Windows operating system handles the translation and triggers the menu-item selection event, also firing the menu option trigger in 4GL. 

But what if you don't have a menu and still want to use key combinations for certain actions? In such cases, you can define them in the Keyboard Translation Table (KTT). However, this approach is more static and harder to maintain. The configured key combinations in the KTT are not visible from the outside. Additionally, 4GL involves checking numbers in the $char register, making the code less verbose. Here's an example: 

Defined in the Keyboard Translation Table, you can have the following lines for Ctrl+K, Ctrl+L, and Ctrl+P: 

 ^130^107 ^USER_KEY^150 

^130^108 ^USER_KEY^156 

^130^112 ^USER_KEY^162 

In the user key trigger, you can define the desired actions: 

 trigger Userkey 

trigger userkey 

   message/info "User key %%$char pressed!" 

   if($char=150) 

     dosome work here 

   endif 

end 

Further details on adding additional text in the KTT can be found in the Uniface documentation: 
https://docs.rocketsoftware.com/bundle/uniface_104/page/zqi1665702981620.html 

User keys 

To address the absence of menus and the need for keyboard accelerators, we’ve added a new section to the usys.ini file: [userkeys]. Here, we explain how to utilize user-defined keys. 

Accelerators activate menu items and subsequently fires the menu’s option trigger. On the other hand, the userkey definition fires the userkey trigger. 

The userkey trigger can also be fired by a keyboard combination defined in the KTT as we saw earlier in this blog. Heres an example of a user key definition in the usys.ini file: 

[userkeys] 
fileopen=Ctrl+O 

When this definition exists, and there is no menu or active menu with the same keyboard combination, pressing Ctrl+O fires the userkey trigger, setting $result to fileopen..  

This approach allows having the same accelerators in Forms with or without menus. However, if a menu with the same accelerator exists, it takes precedence over the user key definitions. The order of precedence is as follows: 

  1. Menu items with an accelerator 

  1. Label text with an underscore, used to set focus to an associated field or default keys for a button. 

  1. User key definition in the usys.ini 

  1. HTML widget property UNIFACEKEYS 

  1. User key definition in the keyboard translation table (KTT) 

Labels on a Form or default keys for buttons take precedence over user keys. Labels with underscored characters indicate that pressing Alt+<char> sets the input focus to the associated field, while buttons with underscored characters imply that pressing Alt+<char> fires the detail trigger. 

The userkeys section can also contain keys like F1... F12, NUMPAD-, NUMPAD/, NUMPAD*, TAB, ESC or cursor keys.  

Function keys are sometimes in use by a widget control. For example, a multiline edit control uses TAB to insert a Tab character, while other controls have no specific handling, and the system will move the keyboard input to the next control in the Form. It is important to choose the right key combination (or single key) to avoid possible conflicts with the Windows operating system or the applications controls. In the appendix of this blog, you will find an overview of the keyboard keys and their possible usage. Also, we’ve added a recommendation to help you, as developer, choose the right key when you do not want to combine the key with Ctrl or Alt. 

The userkey trigger documentation can be found here: https://docs.rocketsoftware.com/bundle/uniface_104/page/niy1665702606431.html 

Uniface keys and the HTML widget 

To pass keystrokes directly to Uniface when using the HTML widget, the property unifacekeys comes into play. Suppose you want to perform a retrieve on Ctrl+R, ensuring this key combination reaches the UNIFACE kernel instead of JavaScript, you can define the following in the widget section: 

Html=uhtml(unifacekeys=Ctrl+R) 

This configuration sends Ctrl+R to the Uniface keyboard translation table. If a user key definition exists for this combination, it takes precedence. The unifacekeys property primarily determines which keys are sent to Uniface instead of JavaScript. The user key definition is always checked for each keystroke in the HTML widget, explaining why it has a higher priority than JavaScript or the unifacekeys property. 

System keys 

Certain key combinations, like Alt+F4 to close a form or Alt+SPACEBAR to activate a menu, are reserved by the operating system and cannot be used for accelerators or user keys. See the appendix for details on the different keys. 

Tips 

When using accelerators or user key definitions, its advisable to provide clear descriptions for the actions. For example, use fileopen=Ctrl+O. In the case of the userkey trigger, this description will appear in the proc-script, making it more readable and easier to maintain. Additionally, check the component for labels or buttons using keyboard shortcuts and avoid conflicting key combinations, as labels take precedence over user key definitions. By using Ctrl+<character> for menus and user keys, you can avoid conflicts between label shortcuts, accelerators, and user keys. 

 Appendix 

In this chapter you’ll find an overview of single keys recognized by UNIFACE. The table is showing the <key>, without modifier like Ctrl or Alt. Of course, you can use these keys in combination with Ctrl or Alt. 

 

Keyboard key as recognized by Uniface 

Information 

Usage possible or recommended as standalone key 

BACKSPACE 

Conflicts in components using edit controls 

No 

TAB 

Many controls are using this internally 

No 

ENTER 

Many controls are using this internally 

No 

ESC 

Can be used as standalone key only when the QUIT trigger on component level returns (-1) 

Yes 

SPACE 

Many controls are using this internally 

No 

SPACEBAR 

Many controls are using this internally 

No 

PGUP 

Multiline, lists and tree controls are using this internally 

No 

PAGEUP 

Multiline, lists and tree controls are using this internally. Ctrl+PAGEUP is used by Tab widget. 

No 

PGDN 

Multiline, lists and tree controls are using this internally 

No 

PAGEDOWN 

Multiline, lists and tree controls are using this internally. Ctrl+PAGEDOWN is used by Tab widget. 

No 

END 

Many controls are using this internally 

No 

HOME 

Many controls are using this internally 

No 

LEFT 

Many controls are using this internally 

No 

UP 

Many controls are using this internally 

No 

RIGHT 

Many controls are using this internally 

No 

DOWN 

Many controls are using this internally 

No 

NUMPAD* 

Can be used but not recommended, conflicts with tree control which use the Shift * for expansion 

No 

NUMPAD- 

Can be used but not recommended 

No 

NUMPAD/ 

Can be used but not recommended 

No 

F1 

Generally used for Help 

Yes 

F2 

Generally used for Rename 

Yes 

F3 

Generally used for Search 

Yes 

F4 

No particular use 

Yes 

F5 

Generally used for Refresh 

Yes 

F6 

Generally used to go to Address Bar 

Yes 

F7 

Generally used for spell check 

Yes 

F8 

No particular use 

Yes 

F9 

Generally used for Compile and Run 

Yes 

F10 

Generally used to activate Menu 

Yes 

F11 

Generally used to exit Full screen 

Yes 

F12 

Generally used for Save 

Yes 


#tofp
0 comments
14 views

Permalink