Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

keyboard navigation in twine story?

Hi, I was wondering if there is a way to navigate in the twine story and change passage with keys? (for example left and right arrow keys to move from one page to another)
thanks in advance

Comments

  • I'm working on something similar -- I'm using specific keys to navigate to my help passage, my navigation, etc. I'm taking a "belt and suspenders" approach where I use HTML accesskeys, with JavaScript key bindings as a backup. Hopefully this will help you get started.

    The accesskey code within a passage looks like this:
    <<if $clue != "">>
    <p id="clue" tabindex=0 accesskey="c">$clue</p>
    <</if>>
    

    It's important to set the tabindex to 0. See http://snook.ca/archives/accessibility_and_usability/elements_focusable_with_tabindex
    for a discussion of the issue.

    My keybinding macro looks like this:
    Macro.add("keyBinder", {
        version: { major: 0, minor: 1, patch: 0 },
        handler: function () {
            try {
    		$(document).keydown(function(event) {
    			 switch(event.keyCode) {
    				case 67:
    					document.getElementById("clue").focus();
     					break;
    				 case 78:
    					 document.getElementById("nav").focus();
    					 break;
    				default: 
    					 /* do nothing */
    			}  
    		});					
            } catch (e) {
                return this.error("keyBinder failed: " + e.message);
            }
        }
    });
    







  • Forgot to add I'm using Sugarcube 2. Other formats may be different.
Sign In or Register to comment.