Reflection Desktop VBA Guide
Attachmate.Reflection.Objects.Emulation.IbmHosts Library / Attachmate.Reflection.Objects.Emulation.IbmHosts Library / KeyboardMapping Object
In This Topic
KeyboardMapping Object
In This Topic
Maps a key to a sequence of one or more input actions.
Example
This example maps a key combination to an action sequence that runs a macro and adds it to the session 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\Reflection\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