SpreadJS 14
Features / Keyboard Actions / Input Mapping
In This Topic
    Input Mapping
    In This Topic

    You can change the keyboard keys that are used to trigger built-in actions to other keys. Actions include navigation, selection, cut, copy, paste, clear, undo, and redo.

    Using Code

    This example specifies the keys for moving left.

    JavaScript
    Copy Code
    //use Control+Shift+b
    spread.commandManager().setShortcutKey("navigationLeft","B".charCodeAt(0),true,true,false,false);
    

    This example changes the action of the default up and down arrow keys for the active cell.

    JavaScript
    Copy Code
    var activeSheet = spread.getActiveSheet();
    //Change the default Up arrow key action to "Page Up" for the active cell.
    spread.commandManager().setShortcutKey("navigationPageUp", GC.Spread.Commands.Key.up, false, false, false, false);
    //Change the default Down arrow key action to "Page Down" for the active cell.
    spread.commandManager().setShortcutKey("navigationPageDown", GC.Spread.Commands.Key.down, false, false, false, false);
    

    This example creates a custom action map for Enter key.

    JavaScript
    Copy Code
    var activeSheet = spread.getActiveSheet();
    
    spread.commandManager().register('myCmd',
           function ColorAction() {                    
                //Click on a cell and press the Enter key.
                activeSheet.getCell(activeSheet.getActiveRowIndex(), activeSheet.getActiveColumnIndex()).backColor("red");
                    }
                );
           //Map the created action to the Enter key.
           spread.commandManager().setShortcutKey('myCmd', GC.Spread.Commands.Key.enter, false, false, false, false);
    

    This example deactivates default key actions by removing default up and down arrow key actions.

    JavaScript
    Copy Code
     $(document).ready(function ()
    {
        var spread =
        new GC.Spread.Sheets.Workbook(document.getElementById("ss"),
        {sheetCount:3});
        var activeSheet = spread.getActiveSheet();
        var manager = spread.commandManager();
        var upKey = manager.setShortcutKey(undefined,
        GC.Spread.Commands.Key.up, false, false,  false, false);
        var downKey =
        manager.setShortcutKey(undefined, GC.Spread.Commands.Key.down, false,
        false, false, false);
    });
    
    See Also