Search input listener providing keyboard support for navigating the dropdown.
19145
function listener(selectivity, input) {
    var keydownCanceled = false;
    var closeSubmenu = null;

    /**
     * Moves a dropdown's highlight to the next or previous result item.
     *
     * @param delta Either 1 to move to the next item, or -1 to move to the previous item.
     */
    function moveHighlight(dropdown, delta) {
        var results = dropdown.results;
        if (!results.length) {
            return;
        }

        var resultItems = [].slice.call(dropdown.el.querySelectorAll('.selectivity-result-item'));

        function scrollToHighlight() {
            var el;
            if (dropdown.highlightedResult) {
                el = findResultItem(resultItems, dropdown.highlightedResult.id);
            } else if (dropdown.loadMoreHighlighted) {
                el = dropdown.$('.selectivity-load-more');
            }

            if (el && el.scrollIntoView) {
                el.scrollIntoView(delta < 0);
            }
        }

        if (dropdown.submenu) {
            moveHighlight(dropdown.submenu, delta);
            return;
        }

        var defaultIndex = delta > 0 ? 0 : resultItems.length - 1;
        var index = defaultIndex;
        var highlightedResult = dropdown.highlightedResult;
        if (highlightedResult) {
            var highlightedResultItem = findResultItem(resultItems, highlightedResult.id);
            index = resultItems.indexOf(highlightedResultItem) + delta;
            if (delta > 0 ? index >= resultItems.length : index < 0) {
                if (dropdown.hasMore) {
                    dropdown.highlightLoadMore();
                    scrollToHighlight();
                    return;
                } else {
                    index = defaultIndex;
                }
            }
        }

        var resultItem = resultItems[index];
        var result = Selectivity.findNestedById(results, selectivity.getRelatedItemId(resultItem));
        if (result) {
            dropdown.highlight(result, { delay: !!result.submenu });
            scrollToHighlight();
        }
    }

    function keyHeld(event) {
        var dropdown = selectivity.dropdown;
        if (dropdown) {
            var keyCode = getKeyCode(event);
            if (keyCode === KEY_BACKSPACE) {
                if (!input.value) {
                    if (dropdown.submenu) {
                        var submenu = dropdown.submenu;
                        while (submenu.submenu) {
                            submenu = submenu.submenu;
                        }
                        closeSubmenu = submenu;
                    }

                    event.preventDefault();
                    keydownCanceled = true;
                }
            } else if (keyCode === KEY_DOWN_ARROW) {
                moveHighlight(dropdown, 1);
            } else if (keyCode === KEY_UP_ARROW) {
                moveHighlight(dropdown, -1);
            } else if (keyCode === KEY_TAB) {
                setTimeout(function() {
                    selectivity.close();
                }, 1);
            } else if (keyCode === KEY_ENTER) {
                event.preventDefault(); // don't submit forms on keydown
            }
        }
    }

    function keyReleased(event) {
        function open() {
            if (selectivity.options.showDropdown !== false) {
                selectivity.open();
            }
        }

        var dropdown = selectivity.dropdown;
        var keyCode = getKeyCode(event);
        if (keydownCanceled) {
            event.preventDefault();
            keydownCanceled = false;

            if (closeSubmenu) {
                closeSubmenu.close();
                selectivity.focus();
                closeSubmenu = null;
            }
        } else if (keyCode === KEY_BACKSPACE) {
            if (!dropdown && selectivity.options.allowClear) {
                selectivity.clear();
            }
        } else if (keyCode === KEY_ENTER && !event.ctrlKey) {
            if (dropdown) {
                dropdown.selectHighlight();
            } else if (selectivity.options.showDropdown !== false) {
                open();
            }

            event.preventDefault();
        } else if (keyCode === KEY_ESCAPE) {
            selectivity.close();

            event.preventDefault();
        } else if (keyCode === KEY_DOWN_ARROW || keyCode === KEY_UP_ARROW) {
            // handled in keyHeld() because the response feels faster and it works with repeated
            // events if the user holds the key for a longer period
            // still, we issue an open() call here in case the dropdown was not yet open...
            open();

            event.preventDefault();
        } else {
            open();
        }
    }

    input.addEventListener('keydown', keyHeld);
    input.addEventListener('keyup', keyReleased);
}
535196
function (inputElem, listener) {

            util.addEvent(inputElem, "input", listener);
            inputElem.onpaste = listener;
            inputElem.ondrop = listener;

            util.addEvent(inputElem, "keypress", listener);
            util.addEvent(inputElem, "keydown", listener);
        }
1271322
function handleKeyEvent() {
        if (!$dropdown) {
            if (!SidebarView.isVisible()) {
                SidebarView.show();
            }

            $("#project-dropdown-toggle").trigger("click");

            $dropdown.focus();
            $links = $dropdown.find("a");
            // By default, select the most recent project (which is at the top of the list underneath Open Folder),
            // but if there are none, select Open Folder instead.
            $dropdownItem = $links.eq($links.length > 1 ? 1 : 0);
            $dropdownItem.addClass("selected");

            // If focusing the dropdown caused a modal bar to close, we need to refocus the dropdown
            window.setTimeout(function () {
                $dropdown.focus();
            }, 0);
        }
    }
327501
function () {
      this.$el.on('mousedown.' + this.id, '.textcomplete-item', $.proxy(this._onClick, this));
      this.$el.on('touchstart.' + this.id, '.textcomplete-item', $.proxy(this._onClick, this));
      this.$el.on('mouseover.' + this.id, '.textcomplete-item', $.proxy(this._onMouseover, this));
      this.$inputEl.on('keydown.' + this.id, $.proxy(this._onKeydown, this));
    }
497060
function searchFormKeyDown(e){
    e = e || window.event;

    // 27 = escape, so hide the form
    if(e.keyCode == 27){
      document.body.removeChild(document.getElementById('search'));
      searchBoxShown = false;

    // 40 = down arrow, select the next item
    }else if(e.keyCode == 40){
      selectNextItem();
      e.preventDefault();
      e.stopPropagation();
      return false;

    // 38 = up arrow, select the previous item
    }else if(e.keyCode == 38){
      selectPreviousItem();
      e.preventDefault();
      e.stopPropagation();
      return false;

    // Most likely a letter typed or deleted in the search box.
    // So queue another search
    }else{
      clearTimeout(searchingTimeout);
      searchingTimeout = setTimeout(doSearch, 150);
    }
  }
850112
function (e) {
                var keyCode = e.domEvent.keyCode;
                if (keyCode === 38 || keyCode === 40 || keyCode === 37 || keyCode === 39) {
                    var index = this.$currentSelectionIndex !== null ? this.$currentSelectionIndex : -1;
                    var indexOffset;
                    if (this.$.scrollDirection === SCROLL_DIRECTION_VERTICAL) {
                        indexOffset = this.$._cols;
                    } else {
                        indexOffset = this.$._rows;
                    }
                    switch (keyCode) {
                        case 38:
                            index -= this.$._cols;
                            break;
                        case 40:
                            index += this.$._cols;
                            break;
                        case 37:
                            index--;
                            break;
                        case 39:
                            index++;
                            break;
                        default:
                            void 0;
                    }
                    if (index < 0) {
                        index = 0;
                    }
                    if (this.$.$dataAdapter && index >= this.$.$dataAdapter.size()) {
                        index = this.$.$dataAdapter.size() - 1;
                    }
                    this._selectItem(index, e.domEvent.shiftKey, false);
                    e.preventDefault();
                    e.stopPropagation();
                }
            }
988855
function onKeyDown(e, that) {
        //On enter send command
        if (e.keyCode === 13) {
            //Remove all may existing suggestions
            that.$debuggerInput.find('.suggestion').remove();
            var com = that.$debuggerInput.val();

            if (com.length > 0) {
                history.push(com);
                historyCurrent = history.length;
                that.log($('<span>').text('>> ' + com));
                that._nodeDebuggerDomain.exec('eval', com);
                //reset the input field
                that.$debuggerInput.val('');
            }
        }
        //On key up/down scroll through history
        if (e.keyCode === 40) {
            historyCurrent++;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = history.length;
                that.$debuggerInput.val('');
            }
            //e.preventDefault();
        }
        if (e.keyCode === 38) {
            historyCurrent--;
            if (history[historyCurrent]) {
                that.$debuggerInput.val(history[historyCurrent]);
            }
            else {
                historyCurrent = 0;
            }
            e.preventDefault();
        }
    }
1026738
function () {
            this.$TextInput._reactToChange.apply(this, arguments);
            var cfg = this._cfg;
            var dropDownIcon = this._getDropdownIcon();
            if (cfg.waiAria && dropDownIcon) {
                if (cfg.disabled) {
                    dropDownIcon.setAttribute("aria-hidden", "true");
                    dropDownIcon.removeAttribute("tabindex");
                } else {
                    dropDownIcon.removeAttribute("aria-hidden");
                    var tabIndex = cfg.tabIndex != null ? this._calculateTabIndex() : "0";
                    dropDownIcon.setAttribute("tabindex", tabIndex);
                }
            }
        }
843167
function keydown (event) {
    switch (event.keyCode) {
      case $mdConstant.KEY_CODE.LEFT_ARROW:
        event.preventDefault();
        incrementIndex(-1, true);
        break;
      case $mdConstant.KEY_CODE.RIGHT_ARROW:
        event.preventDefault();
        incrementIndex(1, true);
        break;
      case $mdConstant.KEY_CODE.SPACE:
      case $mdConstant.KEY_CODE.ENTER:
        event.preventDefault();
        if (!locked) select(ctrl.focusIndex);
        break;
      case $mdConstant.KEY_CODE.TAB:
        // On tabbing out of the tablist, reset hasFocus to reset ng-focused and
        // its md-focused class if the focused tab is not the active tab.
        if (ctrl.focusIndex !== ctrl.selectedIndex) {
          ctrl.focusIndex = ctrl.selectedIndex;
        }
        break;
    }
  }
989303
function keyup(opts, optIdx, e) {
          var elem = opts.$input.get(0),
              elemFocusPosition,
              beforeValue,
              newValue,
              selection,
              selectionLength;

          if ("selectionStart" in elem) {
            // Standard-compliant browsers
            elemFocusPosition = elem.selectionStart;
          } else if (document.selection) {
            // IE
            //elem.focus();
            selection = document.selection.createRange();
            selectionLength = document.selection.createRange().text.length;
            selection.moveStart("character", -elem.value.length);
            elemFocusPosition = selection.text.length - selectionLength;
          }

          beforeValue = elem.value;
          if (opts.pattern in FORMATTER.formatter) {
            newValue = FORMATTER.formatter[opts.pattern].getPatternValue.call(this, opts, optIdx, e, elem.value);
          } else {
            newValue = beforeValue;
          }

          if (newValue != beforeValue) {
            opts.$input.val(newValue).trigger("change");
            setSelectionRange(elem, elemFocusPosition + newValue.length - beforeValue.length);
          }
        }
1098660
function keydownListener(ev) {
      if (isDisabled()) return;
      var keyCodes = $mdConstant.KEY_CODE;

      var changeAmount;
      switch (ev.keyCode) {
        case keyCodes.DOWN_ARROW:
        case keyCodes.LEFT_ARROW:
          ev.preventDefault();
          changeAmount = -step;
          break;
        case keyCodes.UP_ARROW:
        case keyCodes.RIGHT_ARROW:
          ev.preventDefault();
          changeAmount = step;
          break;
        case keyCodes.PAGE_DOWN:
          ev.preventDefault();
          changeAmount = -step * stepPageSize;
          break;
        case keyCodes.PAGE_UP:
          ev.preventDefault();
          changeAmount = step * stepPageSize;
          break;
        case keyCodes.HOME:
          ev.preventDefault();
          ev.stopPropagation();
          updateValue(min);
          break;
        case keyCodes.END:
          ev.preventDefault();
          ev.stopPropagation();
          updateValue(max);
          break;
      }
      if (changeAmount) {
        changeAmount = invert ? -changeAmount : changeAmount;
        if (ev.metaKey || ev.ctrlKey || ev.altKey) {
          changeAmount *= modifierMultiplier;
        }
        ev.preventDefault();
        ev.stopPropagation();
        updateValue(ngModelCtrl.$viewValue + changeAmount);
      }
    }
461568
function handleComboboxKeyDown(event) {
    eventUtils.handleUpDownArrowsKeydown(event, () => {
        const currentSelectedIndex = findIndex(this.state.options, option => option.selected);
        const options = clearComboboxSelections(this.state.options);
        const optionEls = this.el.querySelectorAll(comboboxOptionSelector);
        let selectElementIndex = currentSelectedIndex;

        switch (event.charCode || event.keyCode) {
            // down
            case 40:
                selectElementIndex = traverseOptions(options, currentSelectedIndex, 1);
                break;
            // up
            case 38:
                selectElementIndex = traverseOptions(options, currentSelectedIndex, -1);
                break;
            default:
                break;
        }

        options[selectElementIndex].selected = true;

        this.setState('options', options);
        this.processAfterStateChange(optionEls[selectElementIndex]);
    });

    eventUtils.handleEscapeKeydown(event, () => {
        this.expander.collapse();
        this.el.querySelector(comboboxHostSelector).focus();
    });
}
1103373
public void setOnQueryTextListener(@NonNull final SearchView.OnQueryTextListener listener) {
        if (searchView != null) {
            searchView.setOnQueryTextListener(listener);
        } else if (supportView != null) {
            supportView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
                @Override public boolean onQueryTextSubmit(String query) {
                    return listener.onQueryTextSubmit(query);
                }

                @Override public boolean onQueryTextChange(String newText) {
                    return listener.onQueryTextChange(newText);
                }
            });
        } else {
            throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
        }
    }
1018671
function() {

            var self = this,
                moveToOption = self.list.is(":visible") || !self.options["keydownOpen"];

            return {

                "down": function() {

                    // If the plugin options allow keyboard navigation
                    if (self.moveDown && moveToOption) {

                        self.moveDown();

                    }

                },

                "up": function() {

                     // If the plugin options allow keyboard navigation
                    if (self.moveUp && moveToOption) {

                        self.moveUp();

                    }

                },

                "enter": function() {

                    var activeElem = self.listItems.eq(self.currentFocus);

                    // Updates the dropdown list value
                    self._update(activeElem);

                    if (activeElem.attr("data-preventclose") !== "true") {

                        // Closes the drop down list options list
                        self.close();

                    }

                    // Triggers the `enter` events on the original select box
                    self.triggerEvent("enter");

                },

                "tab": function() {

                    // Triggers the custom `tab-blur` event on the original select box
                    self.triggerEvent("tab-blur");

                    // Closes the drop down list
                    self.close();

                },

                "backspace": function() {

                    // Triggers the custom `backspace` event on the original select box
                    self.triggerEvent("backspace");

                },

                "esc": function() {

                    // Closes the dropdown options list
                    self.close();

                }

            };

        }
919005
private void textFieldSearchTextKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textFieldSearchTextKeyPressed
    switch (evt.getKeyCode()) {
      case KeyEvent.VK_ESCAPE: {
        this.setVisible(false);
        this.baseEditor.requestActive();
        evt.consume();
      }
      break;
      case KeyEvent.VK_ENTER: {
        if (evt.isShiftDown()) {
          findPrev();
        } else {
          findNext();
        }
        evt.consume();
      }
      break;
    }
  }
523412
private void addKeyboardListener(KeyboardAwt keyboard)
    {
        componentForKeyboard.addKeyListener(keyboard);
        componentForKeyboard.requestFocus();
        componentForKeyboard.setFocusTraversalKeysEnabled(false);
    }
880759
def eventFilter(self, widget, event):
        
        if event.type() == QEvent.KeyPress:
            key = event.key()
            shift = event.modifiers() & Qt.ShiftModifier

            if key == Qt.Key_Return:
                if shift:
                    self.return_shift_pressed.emit()
                else:
                    self.return_pressed.emit()

            if key == Qt.Key_Tab:
                if self.search_text.hasFocus():
                    self.replace_text.set_current_text(
                        self.search_text.currentText())
                self.focusNextChild()

        return super(FindReplace, self).eventFilter(widget, event)