No internet connection
  1. Home
  2. Script Sharing

Modular way of adding keyboard modifiers to a template

By Loran Keuning @Loran_Keuning
    2025-02-22 12:52:41.599Z

    This method uses a 'list' property to assign multiple variations of the script or different scripts to modifier keys inside one template. In this example script the user can add and choose a modifier key and the command to run when that key is hold. The list property is called 'modifier' and the keyboard modifier is called 'kModifier'. (sadly the template crashes when you try to do this with callback properties)

    // Detect the active modifier
    const activeModifier = event.keyboardState.asString;
    
    // Retrieve the matching configuration
    const selectedConfig = (event.props.modifier || []).find(config => config.kModifier === activeModifier);
    
    // If a matching config is found, apply its properties to event.props
    if (selectedConfig) Object.assign(event.props, selectedConfig);
    
    try {
    sf.soundflow.runCommand({
        commandId: event.props.command.commandId,
        async: Boolean(event.props.aSync),
        executionMode: event.props.executionMode,
        onCancel: event.props.onCancel,
        onError: event.props.onError,
    });
    } catch (Error){
        log ("No Command has been Found")
    };
    
    • 1 replies
    1. Loran Keuning @Loran_Keuning
        2025-05-18 10:37:08.807Z

        UPDATE:

        A recent update fixed the usage of the callback function property in a list property. So now it's possible to use this method with callback commands instead. Making the template even more modular.

        Template Script:

        // Detect the active modifier
        const activeModifier = event.keyboardState.asString;
        
        // Retrieve the matching configuration
        const selectedConfig = (event.props.modifier || []).find(config => config.kModifier === activeModifier);
        
        // If a matching config is found, apply its properties to event.props
        if (selectedConfig) Object.assign(event.props, selectedConfig);
        
        const { command } = event.props;
        
        try {
        command();
        } catch (Error){
            log (Error)
        };
        

        How The Template Looks Example:

        Template Settings: