src/Keyboard.js
function interpret_event() {

        // Peek at first event in log
        var first = eventLog[0];
        if (!first)
            return null;

        // Keydown event
        if (first instanceof KeydownEvent) {

            var keysym = null;
            var accepted_events = [];

            // If event itself is reliable, no need to wait for other events
            if (first.reliable) {
                keysym = first.keysym;
                accepted_events = eventLog.splice(0, 1);
            }

            // If keydown is immediately followed by a keypress, use the indicated character
            else if (eventLog[1] instanceof KeypressEvent) {
                keysym = eventLog[1].keysym;
                accepted_events = eventLog.splice(0, 2);
            }

            // If keydown is immediately followed by anything else, then no
            // keypress can possibly occur to clarify this event, and we must
            // handle it now
            else if (eventLog[1]) {
                keysym = first.keysym;
                accepted_events = eventLog.splice(0, 1);
            }

            // Fire a key press if valid events were found
            if (accepted_events.length > 0) {

                if (keysym) {

                    // Fire event
                    release_simulated_altgr(keysym);
                    var defaultPrevented = !guac_keyboard.press(keysym);
                    recentKeysym[first.keyCode] = keysym;

                    // If a key is pressed while meta is held down, the keyup will
                    // never be sent in Chrome, so send it now. (bug #108404)
                    if (guac_keyboard.modifiers.meta && keysym !== 0xFFE7 && keysym !== 0xFFE8)
                        guac_keyboard.release(keysym);

                    // Record whether default was prevented
                    for (var i=0; i<accepted_events.length; i++)
                        accepted_events[i].defaultPrevented = defaultPrevented;

                }

                return first;

            }

        } // end if keydown

        // Keyup event
        else if (first instanceof KeyupEvent) {

            // Release specific key if known
            var keysym = first.keysym;
            if (keysym) {
                guac_keyboard.release(keysym);
                first.defaultPrevented = true;
            }

            // Otherwise, fall back to releasing all keys
            else {
                guac_keyboard.reset();
                return first;
            }

            return eventLog.shift();

        } // end if keyup

        // Ignore any other type of event (keypress by itself is invalid)
        else
            return eventLog.shift();

        // No event interpreted
        return null;

    }
function interpret_event() {

        // Peek at first event in log
        var first = eventLog[0];
        if (!first)
            return null;

        // Keydown event
        if (first instanceof KeydownEvent) {

            var keysym = null;
            var accepted_events = [];

            // If event itself is reliable, no need to wait for other events
            if (first.reliable) {
                keysym = first.keysym;
                accepted_events = eventLog.splice(0, 1);
            }

            // If keydown is immediately followed by a keypress, use the indicated character
            else if (eventLog[1] instanceof KeypressEvent) {
                keysym = eventLog[1].keysym;
                accepted_events = eventLog.splice(0, 2);
            }

            // If keydown is immediately followed by anything else, then no
            // keypress can possibly occur to clarify this event, and we must
            // handle it now
            else if (eventLog[1]) {
                keysym = first.keysym;
                accepted_events = eventLog.splice(0, 1);
            }

            // Fire a key press if valid events were found
            if (accepted_events.length > 0) {

                if (keysym) {

                    // Fire event
                    release_simulated_altgr(keysym);
                    var defaultPrevented = !guac_keyboard.press(keysym);
                    recentKeysym[first.keyCode] = keysym;

                    // If a key is pressed while meta is held down, the keyup will
                    // never be sent in Chrome, so send it now. (bug #108404)
                    if (guac_keyboard.modifiers.meta && keysym !== 0xFFE7 && keysym !== 0xFFE8)
                        guac_keyboard.release(keysym);

                    // Record whether default was prevented
                    for (var i=0; i<accepted_events.length; i++)
                        accepted_events[i].defaultPrevented = defaultPrevented;

                }

                return first;

            }

        } // end if keydown

        // Keyup event
        else if (first instanceof KeyupEvent) {

            // Release specific key if known
            var keysym = first.keysym;
            if (keysym) {
                guac_keyboard.release(keysym);
                first.defaultPrevented = true;
            }

            // Otherwise, fall back to releasing all keys
            else {
                guac_keyboard.reset();
                return first;
            }

            return eventLog.shift();

        } // end if keyup

        // Ignore any other type of event (keypress by itself is invalid)
        else
            return eventLog.shift();

        // No event interpreted
        return null;

    }
function interpret_event ( ) { // Peek at first event in log var first = eventLog [ 0 ] ; if ( ! first ) return null ; // Keydown event if ( first instanceof KeydownEvent ) { var keysym = null ; var accepted_events = [ ] ; // If event itself is reliable, no need to wait for other events if ( first . reliable ) { keysym = first . keysym ; accepted_events = eventLog . splice ( 0 , 1 ) ; } // If keydown is immediately followed by a keypress, use the indicated character else if ( eventLog [ 1 ] instanceof KeypressEvent ) { keysym = eventLog [ 1 ] . keysym ; accepted_events = eventLog . splice ( 0 , 2 ) ; } // If keydown is immediately followed by anything else, then no // keypress can possibly occur to clarify this event, and we must // handle it now else if ( eventLog [ 1 ] ) { keysym = first . keysym ; accepted_events = eventLog . splice ( 0 , 1 ) ; } // Fire a key press if valid events were found if ( accepted_events . length > 0 ) { if ( keysym ) { // Fire event release_simulated_altgr ( keysym ) ; var defaultPrevented = ! guac_keyboard . press ( keysym ) ; recentKeysym [ first . keyCode ] = keysym ; // If a key is pressed while meta is held down, the keyup will // never be sent in Chrome, so send it now. (bug #108404) if ( guac_keyboard . modifiers . meta && keysym !== 0xFFE7 && keysym !== 0xFFE8 ) guac_keyboard . release ( keysym ) ; // Record whether default was prevented for ( var i = 0 ; i < accepted_events . length ; i ++ ) accepted_events [ i ] . defaultPrevented = defaultPrevented ; } return first ; } } // end if keydown // Keyup event else if ( first instanceof KeyupEvent ) { // Release specific key if known var keysym = first . keysym ; if ( keysym ) { guac_keyboard . release ( keysym ) ; first . defaultPrevented = true ; } // Otherwise, fall back to releasing all keys else { guac_keyboard . reset ( ) ; return first ; } return eventLog . shift ( ) ; } // end if keyup // Ignore any other type of event (keypress by itself is invalid) else return eventLog . shift ( ) ; // No event interpreted return null ; }
Reads through the event log, interpreting the first event, if possible,
and returning that event. If no events can be interpreted, due to a
total lack of events or the need for more events, null is returned. Any
interpreted events are automatically removed from the log.

@private
@return {KeyEvent}
The first key event in the log, if it can be interpreted, or null
otherwise.
Reads through the event log interpreting the first event if possible and returning that event . If no events can be interpreted due to a total lack of events or the need for more events null is returned . Any interpreted events are automatically removed from the log .