function onDocumentKeyDown()

in js/reveal.js [5096:5317]


	function onDocumentKeyDown( event ) {

		// If there's a condition specified and it returns false,
		// ignore this event
		if( typeof config.keyboardCondition === 'function' && config.keyboardCondition(event) === false ) {
			return true;
		}

		// Shorthand
		var keyCode = event.keyCode;

		// Remember if auto-sliding was paused so we can toggle it
		var autoSlideWasPaused = autoSlidePaused;

		onUserInput( event );

		// Is there a focused element that could be using the keyboard?
		var activeElementIsCE = document.activeElement && document.activeElement.contentEditable !== 'inherit';
		var activeElementIsInput = document.activeElement && document.activeElement.tagName && /input|textarea/i.test( document.activeElement.tagName );
		var activeElementIsNotes = document.activeElement && document.activeElement.className && /speaker-notes/i.test( document.activeElement.className);

		// Whitelist specific modified + keycode combinations
		var prevSlideShortcut = event.shiftKey && event.keyCode === 32;
		var firstSlideShortcut = ( event.metaKey || event.ctrlKey ) && keyCode === 37;
		var lastSlideShortcut = ( event.metaKey || event.ctrlKey ) && keyCode === 39;

		// Prevent all other events when a modifier is pressed
		var unusedModifier = 	!prevSlideShortcut && !firstSlideShortcut && !lastSlideShortcut &&
								( event.shiftKey || event.altKey || event.ctrlKey || event.metaKey );

		// Disregard the event if there's a focused element or a
		// keyboard modifier key is present
		if( activeElementIsCE || activeElementIsInput || activeElementIsNotes || unusedModifier ) return;

		// While paused only allow resume keyboard events; 'b', 'v', '.'
		var resumeKeyCodes = [66,86,190,191];
		var key;

		// Custom key bindings for togglePause should be able to resume
		if( typeof config.keyboard === 'object' ) {
			for( key in config.keyboard ) {
				if( config.keyboard[key] === 'togglePause' ) {
					resumeKeyCodes.push( parseInt( key, 10 ) );
				}
			}
		}

		if( isPaused() && resumeKeyCodes.indexOf( keyCode ) === -1 ) {
			return false;
		}

		var triggered = false;

		// 1. User defined key bindings
		if( typeof config.keyboard === 'object' ) {

			for( key in config.keyboard ) {

				// Check if this binding matches the pressed key
				if( parseInt( key, 10 ) === keyCode ) {

					var value = config.keyboard[ key ];

					// Callback function
					if( typeof value === 'function' ) {
						value.apply( null, [ event ] );
					}
					// String shortcuts to reveal.js API
					else if( typeof value === 'string' && typeof Reveal[ value ] === 'function' ) {
						Reveal[ value ].call();
					}

					triggered = true;

				}

			}

		}

		// 2. Registered custom key bindings
		if( triggered === false ) {

			for( key in registeredKeyBindings ) {

				// Check if this binding matches the pressed key
				if( parseInt( key, 10 ) === keyCode ) {

					var action = registeredKeyBindings[ key ].callback;

					// Callback function
					if( typeof action === 'function' ) {
						action.apply( null, [ event ] );
					}
					// String shortcuts to reveal.js API
					else if( typeof action === 'string' && typeof Reveal[ action ] === 'function' ) {
						Reveal[ action ].call();
					}

					triggered = true;
				}
			}
		}

		// 3. System defined key bindings
		if( triggered === false ) {

			// Assume true and try to prove false
			triggered = true;

			// P, PAGE UP
			if( keyCode === 80 || keyCode === 33 ) {
				navigatePrev();
			}
			// N, PAGE DOWN
			else if( keyCode === 78 || keyCode === 34 ) {
				navigateNext();
			}
			// H, LEFT
			else if( keyCode === 72 || keyCode === 37 ) {
				if( firstSlideShortcut ) {
					slide( 0 );
				}
				else if( !isOverview() && config.navigationMode === 'linear' ) {
					navigatePrev();
				}
				else {
					navigateLeft();
				}
			}
			// L, RIGHT
			else if( keyCode === 76 || keyCode === 39 ) {
				if( lastSlideShortcut ) {
					slide( Number.MAX_VALUE );
				}
				else if( !isOverview() && config.navigationMode === 'linear' ) {
					navigateNext();
				}
				else {
					navigateRight();
				}
			}
			// K, UP
			else if( keyCode === 75 || keyCode === 38 ) {
				if( !isOverview() && config.navigationMode === 'linear' ) {
					navigatePrev();
				}
				else {
					navigateUp();
				}
			}
			// J, DOWN
			else if( keyCode === 74 || keyCode === 40 ) {
				if( !isOverview() && config.navigationMode === 'linear' ) {
					navigateNext();
				}
				else {
					navigateDown();
				}
			}
			// HOME
			else if( keyCode === 36 ) {
				slide( 0 );
			}
			// END
			else if( keyCode === 35 ) {
				slide( Number.MAX_VALUE );
			}
			// SPACE
			else if( keyCode === 32 ) {
				if( isOverview() ) {
					deactivateOverview();
				}
				if( event.shiftKey ) {
					navigatePrev();
				}
				else {
					navigateNext();
				}
			}
			// TWO-SPOT, SEMICOLON, B, V, PERIOD, LOGITECH PRESENTER TOOLS "BLACK SCREEN" BUTTON
			else if( keyCode === 58 || keyCode === 59 || keyCode === 66 || keyCode === 86 || keyCode === 190 || keyCode === 191 ) {
				togglePause();
			}
			// F
			else if( keyCode === 70 ) {
				enterFullscreen();
			}
			// A
			else if( keyCode === 65 ) {
				if ( config.autoSlideStoppable ) {
					toggleAutoSlide( autoSlideWasPaused );
				}
			}
			else {
				triggered = false;
			}

		}

		// If the input resulted in a triggered action we should prevent
		// the browsers default behavior
		if( triggered ) {
			event.preventDefault && event.preventDefault();
		}
		// ESC or O key
		else if ( ( keyCode === 27 || keyCode === 79 ) && features.transforms3d ) {
			if( dom.overlay ) {
				closeOverlay();
			}
			else {
				toggleOverview();
			}

			event.preventDefault && event.preventDefault();
		}

		// If auto-sliding is enabled we need to cue up
		// another timeout
		cueAutoSlide();

	}