Forum Discussion

RachelWeiss-de5's avatar
RachelWeiss-de5
Community Member
2 months ago

Press Key Trigger: Capital Letters

Hi!

 

I am using the press key trigger in my storyline project. But when the user types in the letter using shift to capitalize it, the options don't show up. The options only appear when the user types in lower case or uses the capslock. Is there a way for the trigger to work for when the user types it in lowercase or uses shift to capitalize?

 

Thanks!

 

  • JesseWu's avatar
    JesseWu
    Community Member
    // Function to set the Storyline variable
    function setStorylineVariable(variableName, value) {
        GetPlayer().SetVar(variableName, value);
    }
    
    // Check if listeners are already added
    if (!window.keyListenersAdded) {
        // Combined event listener for keydown and keyup
        document.addEventListener('keydown', function(event) {
            if (event.key === 'A' || event.key === 'a') {
                setStorylineVariable('isKeyAPressed', true);
            }
        });
    
        document.addEventListener('keyup', function(event) {
            if (event.key === 'A' || event.key === 'a') {
                setStorylineVariable('isKeyAPressed', false);
            }
        });
    
        // Mark listeners as added
        window.keyListenersAdded = true;
    }

    Personal approach:

    Introduce a new T/F variable with this JS script: When key A is pressed, set it to true; When released, set it to false.

    The new trigger will be: When variable changes, if isKeyAPressed is true, [exec function here].