Forum Discussion
RachelWeiss-de5
3 months agoCommunity Member
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 ...
JesseWu
3 months agoCommunity 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].