I'm looking into trying to bind the escape key to the options menu link I have in the SugarCube StoryCaption special passage.
Does anyone have any tips?
note: The above assumes that your StoryCaption passage contains a options markup link, if the passage title of your options passage is something different then you will need to change the "options" value reference of the data-passage="options" part of the above code.
I found this code to work with just random trial and error:
Am I doing it right?
As to your extended selector question. greyelf is correct, the "Day 2" and "Day 3" selectors would match on the entire document, which isn't what you're trying to do. As a slightly different take on their example, you could also do something like the following: I'm not saying that's better than greyelf's example, just different.
Alternatively, if all of your links are similar (i.e. "Day …"), then you could simply use the prefix match selector to match all values which start in a particular way:
Caveat: All of the examples given so far will trigger a click for all matched elements, so you should ensure that only one of those exist at any given time.
The only time I might have multiple same links on the page is if I keep a set of visibility hidden links in StoryCaption these shortcuts link to, and have another set of visible links down the bottom of the passage area the player can click to.
(Mostly because putting stuff in storycaption doesn't fit my design, but i still want to keep shortcuts active on all passages even if I don't actually have a proper passage showing.)
I'm aware of what will happen if someone holds the esc key down with keydown, but it feels snappier than keyup, and I don't think anyone will do that.
Eg if I use this code to debounce "X" with a value of 1 second, and I spam X 10 times, I then need to wait 10 seconds as the debounces stack.
OR, just as useful an answer: Is there a way to bind keys to <<click>> macro links? If so then I can just write my own debounce function with $set variables.