Passing parameters to keyboard shortcut callback

Posted by: tadekunle on 8 November 2021, 10:19 am EST

  • Posted 8 November 2021, 10:19 am EST


    I am trying to define custom keyboard shortcuts to be used in spreadjs. I went through this example and i see the callback functions have parameters in their definition but i dont see where the parameters are passed when the command is being registered. I was wondering how the passing of parameters works with the callback functions of keyboard shortcuts and if it is possible for me to pass in an object to the callback function.

    I also tried to define keyboard shortcuts for certain keys like the backslash (alt + /), equals (alt + =) and period (alt + .) keys but they weren't working. Is it possible for me to have special keys like i mentioned above used in keyboard shortcuts?

    Thanks for your help
  • Replied 9 November 2021, 4:59 am EST


    When using the keyboard shortcuts, SpreadJS calls the registered execute callback automatically by passing the correct callback parameter options. The options object includes the sheetName on which action is invoked.
    However, it is possible to pass custom options when we explicitly call the command using the execute method.
    API reference:

    I've prepared a sample to demonstrate how you could register alt + = combination for custom action. Please refer to the same and let me know if you face any issues:

  • Replied 10 November 2021, 8:53 am EST


    Thanks for the alt + = demo, that worked.

    However concerning the first issue I am still unclear of the instructions. Right now I am trying to register a callback function to a custom keyboard shortcut by calling the setShortcutKey() and registerCommand() methods like so

    commandManager.register('altR', this.sampleShortcutAlertUser);

    where this.sampleAlertUser is the callback function that I want to pass parameters into. How can I pass my custom parameters into this callback function that will be triggered when a keyboard shortcut is pressed?

    Thank you.
  • Marked as Answer

    Replied 11 November 2021, 9:39 pm EST


    We are sorry but we could not pass parameters to shortcutkeys callback however if the values are not getting changed you could store the values as closure inside the execute function.

Need extra support?

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

Learn More

Forum Channels