You can programmatically map macros or other actions to keys or key combinations. This allows you to modify how a key is mapped without replacing a user's customized keyboard map.
If you prefer to run macros in pre-configured sessions instead of creating your own sessions, you can download the VBA Sample Sessions and open the following sessions:
change-keyboard-mapping.rd3x (IBM)
change-keyboard-mapping-for-specific-screens.rd3x (IBM)
change-keyboard-mapping.rdox (Open Systems)
change-keyboard-mapping-when-certain-strings-are-received.rdox (Open Systems)
The download package contains everything you need to run the macros in these files. See Download the VBA Sample Sessions.
This walkthrough shows several ways to change keyboard maps.
This example maps the Ctrl+B key to a simple macro that gets text from the screen and displays it in a message box.
Instead of manually running a macro to map a key, you can use events to programmatically map a key when a session starts. This sample runs the MapKeyToMacro subroutine (shown in Change a Key Mapping) as the session connects.
You can use events to programmatically map a key when specific screens open (IBM) or when certain strings are received (Open Systems). This sample runs the MapKeyToMacro subroutine shown in Change a Key Mapping to assign an action to a key when a specific screen opens (for IBM sessions) or when a specific string is received (for Open Systems sessions).
To map a keyboard combination, you'll need to:
To set up the action, we need to define the action and then add it to an action sequence so we can map it to a key.
First, you define the action you want to map by creating an InputMapAction object and defining its properties. The InputMapActionID enum defines a number of actions that you can assign to input maps (keyboard or mouse maps). Some of these actions, like the RunMacroAction, require specific parameters. You can get information about which parameters are required and how to set them in the Help description for each enum item. You'll need to set these parameters in the order in which they are listed in the Help.
In our example, the Help for the RunMacroAction enum indicates we need to add three parameters to the InputMap Action object:
In our example, we set these parameters in the order in which they are listed in the enum description, using the three methods for adding parameters on the InputMapAction object: AddParameter, AddParameterAsInteger, and AddParameterAsBoolean.
After we have defined the action, we need to add it to an action sequence so we can map it to the key we want to use. We do this by creating an InputMapActionSequence object and adding the InputMapAction that we created to this object.
To set up a keyboard shortcut, we need to create a new KeyBoardMapping object and add it to the session keyboard map.
The KeyBoardMapping object has properties that we can use to set the key associated with the keyboard mapping and set the action sequence associated with the keyboard mapping.
First, we set the Key property to items defined in the InfoConnect Keys enumeration. Then we set the Mapping property to the sequence we created for the action. Finally, we add the new mapping to the session keyboard map.
You can use this same approach to map any action to your keyboard.