InfoConnect VBA Guide
Attachmate.Reflection.Objects.Emulation.IbmHosts Library / KeyboardMapper Object / AddMapping Method
A KeyboardMapping object that has a mapping between a key sequence and a set of actions to perform when that key sequence is pressed in a host session.
Example
In This Topic
    AddMapping Method (KeyboardMapper)
    In This Topic
    Adds a key mapping to the current keyboard map.
    Syntax
    expression.AddMapping( _
       ByVal mapping As KeyboardMapping _
    ) 
    where expression is a variable that represents a KeyboardMapper Object

    Parameters

    mapping
    A KeyboardMapping object that has a mapping between a key sequence and a set of actions to perform when that key sequence is pressed in a host session.
    Remarks
    A key can also be remapped to do nothing if the InputMapSequenceAction specified in mapping.Mapping has no InputMapActions added to it.
    Example
    This example adds a mapping for a key combination that runs a macro to a keyboard map.
    Public Sub MapKeyToMacro()
        Dim kbmapping As KeyboardMapping
        Dim sequence As InputMapActionSequence
        Dim action As InputMapAction
        Dim path As String
        Dim isKeyInMap As Boolean
        
        Dim key, altKey As Keys
        
        'Define two key combinations in case the first key combination is mapped
        key = Keys_Control + Keys_B
        altKey = Keys_Control + Keys_D
        
        'Se the file path and name for the new keyboard map
        path = Environ$("USERPROFILE") & "\Documents\Micro Focus\InfoConnect\Keyboard Maps\" & "myKeyboardMap.xkb"
     
        Set kbmapping = New KeyboardMapping
        Set sequence = New InputMapActionSequence
                             
        'Set up the action to run a recorded macro named Test in a module named Module1
        Set action = New InputMapAction
        action.ActionId = InputMapActionID_RunMacroAction
        action.AddParameter "Module1.Test" 'This is the name of the module the macro is in and the macro name
        action.AddParameterAsInteger MacroEnumerationOption.MacroEnumerationOption_Document 'Look for the macro in this Session project
        action.AddParameterAsBoolean False 'Don't ask for any input at runtime
        sequence.Add action 'Add the action to the action sequence
        
        'If the key combination is in the map, use the alternate
        isKeyInMap = ThisIbmTerminal.KeyboardMapper.contains(key)
        If isKeyInMap = True Then
            Debug.Print "in map"
            key = altKey
        End If
        
        'Assign the key combination to the new action
        kbmapping.key = key
     
        'Map the key assigned  to the keyboard mapping to the sequence
        Set kbmapping.mapping = sequence
     
        'Add the new mapping to the session keyboard map
        ThisIbmTerminal.KeyboardMapper.AddMapping kbmapping
        
        'Save the new file
        ThisIbmTerminal.KeyboardMapper.SaveAs (path)
                              
    End Sub
    See Also