Skip to main content
Commonmark migration
Source Link

###Short answer:

Short answer:

###Slightly longer answer:

Slightly longer answer:

###Short answer:

###Slightly longer answer:

Short answer:

Slightly longer answer:

Source Link

###Short answer:

Keyboard shortcuts already exist:

stackoverflow.com/users/preferences/current => "Enable keyboard shortcuts" – Cody Gray

And we can't change the default shortcuts:

No settings for changing the built-in keyboard shortcuts, no. [snip] – Cody Gray

###Slightly longer answer:

Rolled my own:

Here is a user.js script that allows the user to go up/down the list of questions and press enter "click" the link.

Originally I tried to extend the StackExchange.keyboardShortcuts function to trigger on the up/down keys, then to trigger keydown (e.which=74 / 75) but couldn't find the element that this event was bound to.

// ==UserScript==
// @name StackOverflow Keyboard up/down Control
// @namespace [email protected]
// @description Allow user to tab through questions using the up/down keys of their keyboard.
// @include https://stackoverflow.com/*
// ==/UserScript==

// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
  var script = document.createElement("script");
  script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "window.jQ=jQuery.noConflict(true);(" + callback.toString() + ")();";
    document.body.appendChild(script);
  }, false);
  document.body.appendChild(script);
}


// the guts of this userscript
function main() {
  var currentQuestionIndex = -1,
    $questions = jQuery('.question-summary'),
    questionLength = $questions.length - 1;


  jQuery('body')

    //on down/up press, select the next/previous (respectively) question
    .on('keydown', function(e) {
      if (e.which == 38 || e.which == 40) {
        currentQuestionIndex += (e.which == 38 ? -1 /*up*/ : e.which == 40 /*down*/ ? 1 : 0);
        if (currentQuestionIndex < 0) {
          currentQuestionIndex = 0;
        }
        if (currentQuestionIndex > questionLength) {
          currentQuestionIndex = questionLength;
        }

        $questions.removeClass('keyboard-selected').eq(currentQuestionIndex).addClass('keyboard-selected');
      }
    })

    //when pressing 'enter' on highlighted link, click it.
    .on('keydown', function(e) {
      //enter key
      if (e.which == 13) {
        $questions.filter('.keyboard-selected').find('.question-hyperlink')[0].click();
      }
    });
}

// load jQuery and execute the main function
addJQuery(main);