@Override
    public void keyPressed(final KeyEvent event) {
      if (event.getKeyCode() == KeyEvent.VK_RIGHT) {

        if (caretPosition
            != (2 * registerModel.getRegisterInformation(editedRegister).getRegisterSize())) {
          caretPosition++;
        }

        event.consume(); // Consume the event to avoid scrolling

        caret.setVisible(true);
        repaint();
      } else if (event.getKeyCode() == KeyEvent.VK_LEFT) {

        if (caretPosition != 0) {
          caretPosition--;
        }

        event.consume(); // Consume the event to avoid scrolling

        caret.setVisible(true);
        repaint();
      } else if (event.getKeyCode() == KeyEvent.VK_ENTER) {

        if (editedRegister == -1) {
          if (highlightedRegister != -1) {
            enterEditMode(highlightedRegister);
          }
        } else {
          leaveEditMode(true);
        }

        repaint();
      } else if (isHexChar(event.getKeyChar())) {
        final int regSize = registerModel.getRegisterInformation(editedRegister).getRegisterSize();

        if (caretPosition == (2 * regSize)) {
          return;
        }

        // Get the input value
        final long val = hexToValue(event.getKeyChar());

        // Four bits are relevant for each input character.
        final long relevantBits = (regSize * 8) - 4 - (caretPosition * 4);

        // Find a mask for the relevant bits
        final long mask = 0xFL << relevantBits;

        // Shift the input value into the correct bits.
        final long shiftedNew = val << relevantBits;

        // Calculate the new value.
        editValue = editValue.and(BigInteger.valueOf(~mask)).or(BigInteger.valueOf(shiftedNew));

        caretPosition++;

        caret.setVisible(true);
        repaint();
      }
    }
Tests whether a character is a valid hex input value.

@param c The character to test.
@return True, if the character is a valid hex input value. False, otherwise.
java/zylib/src/main/java/com/google/security/zynamics/zylib/gui/JRegisterView/JRegisterView.java