Create keyboard shortcut for CTRL + plus

Posted by: stein on 18 September 2018, 12:59 am EST

    • Post Options:
    • Link

    Posted 18 September 2018, 12:59 am EST

    Hello,

    i’ve got a question regarding keyboard shortcuts. i want to add a shortcut (similar to ms excel) to create a new row with CTRL + plus. I’m not able to archive this with this way:

    commandManager.setShortcutKey('addRow', '+'.charCodeAt(0), true, false, false, false);
    

    is this a reserved shortcut (for zoom)? or could i overwrite it?

    thanks

  • Posted 19 September 2018, 12:47 am EST

    Hello,

    You can create custom command for the action as shown in the example here:

    var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"),{sheetCount:3});
    var activeSheet = spread.getActiveSheet();
    
    spread.commandManager().register('myCmd',
                    function AddRow() {                   
                        //Click on a cell and press the Enter key.
                        activeSheet.addRows(0, 2);
                    }
                );
    
    
    spread.commandManager().setShortcutKey('myCmd', GC.Spread.Commands.Key.plus, true, false, false, false);
    
    

    Thanks,

    Deepak Sharma

  • Posted 19 September 2018, 8:31 pm EST

    thanks for your example but i tried it and it isn’t working. the browser catches always the shortcut as zoom event

  • Posted 20 September 2018, 7:30 pm EST

    Hello,

    You can handle the KeyDown event for Spread div and look for Ctrl+Plus key. You can use the code as shown below:

    
     <script type="text/javascript">
            var spread, sheet;
            window.onload = function () {
                 spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
                 sheet = spread.getActiveSheet();    
                 sheet.setValue(1, 1, "Test"); 
    
            }
            function keyDownFunction(event)
            {        
                if (event.ctrlKey && event.keyCode == 107) {             
                    sheet.addRows(0, 2);
                    event.returnValue = false;                    
                    }
          }   
        </script>
    </head>
    <body>
        <div id="ss" onkeydown="keyDownFunction(event)"></div>
    </body>
    
    

    I hope it helps!

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels