if (this.caretChar != this.editingCaretChar) { insertCharacter(); }
	protected boolean handleKeyPressed(int keyCode, int gameAction) {		//#ifndef tmp.directInput			if ((gameAction == Canvas.UP && keyCode != Canvas.KEY_NUM2) 					|| (gameAction == Canvas.DOWN && keyCode != Canvas.KEY_NUM8)					|| (gameAction == Canvas.LEFT && keyCode != Canvas.KEY_NUM4)					|| (gameAction == Canvas.RIGHT && keyCode != Canvas.KEY_NUM6) ) {				return false;			}		//#endif		if (gameAction == Canvas.FIRE				&& keyCode != Canvas.KEY_NUM5				&& this.defaultCommand != null 				&& this.itemCommandListener != null) 		{			this.itemCommandListener.commandAction(this.defaultCommand, this);			return true;		}		// ignore all command keys:		//#ifdef polish.hasCommandKeyEvents			//#foreach key in polish.keys.CommandKeys				//#= if ( keyCode == ${ key } ) {				//#		return false;				//# }			//#next key		//#endif		//#if tmp.allowDirectInput			//# if (this.enableDirectInput) {		//#endif				//#ifdef tmp.directInput					synchronized ( this.lock ) {					//#if polish.key.ChangeNumericalAlphaInputModeKey:defined						//#= if (keyCode == ${polish.key.ChangeNumericalAlphaInputModeKey} && !this.isNumeric && !this.isUneditable) {							if (this.inputMode == MODE_NUMBERS) {								this.inputMode = MODE_LOWERCASE;							} else {								this.inputMode = MODE_NUMBERS;							}							//#if polish.TextField.showInputInfo != false								updateInfo();							//#endif							if (this.caretChar != this.editingCaretChar) {								insertCharacter();							}							if (this.inputMode == MODE_FIRST_UPPERCASE) {								this.nextCharUppercase = true;							} else {								this.nextCharUppercase = false;							}							//# return true;						//# }					//#endif					//#if polish.key.ChangeNumericalAlphaInputModeKey:defined						//#= if ( keyCode == KEY_CHANGE_MODE && !this.isNumeric && !this.isUneditable && (!(KEY_CHANGE_MODE == Canvas.KEY_NUM0 && this.inputMode == MODE_NUMBERS)) ) {					//#else					if ( keyCode == KEY_CHANGE_MODE && !this.isNumeric && !this.isUneditable) {					//#endif						if (this.nextCharUppercase && this.inputMode == MODE_LOWERCASE) {							this.nextCharUppercase = false;						} else {							this.inputMode++;													}						//#if polish.key.ChangeNumericalAlphaInputModeKey:defined							if (this.inputMode > MODE_UPPERCASE) {								this.inputMode = MODE_LOWERCASE;							}						//#else							if (this.inputMode > MODE_NUMBERS) {								this.inputMode = MODE_LOWERCASE;							}						//#endif						//#if polish.TextField.showInputInfo != false							updateInfo();						//#endif						if (this.caretChar != this.editingCaretChar) {							insertCharacter();						}						if (this.inputMode == MODE_FIRST_UPPERCASE) {							this.nextCharUppercase = true;						} else {							this.nextCharUppercase = false;						}						return true;					}					int currentLength = (this.text == null ? 0 : this.text.length());					if (this.inputMode == MODE_NUMBERS && !this.isUneditable) {						if (currentLength < this.maxSize 								&& ( keyCode >= Canvas.KEY_NUM0 && keyCode <= Canvas.KEY_NUM9 ) ) 						{							this.caretChar = Integer.toString( keyCode - Canvas.KEY_NUM0 ).charAt( 0 );							//#ifdef polish.css.font-bitmap								if (this.bitMapFont != null) {									this.caretViewer = this.bitMapFont.getViewer("" + this.caretChar);								}							//#endif							insertCharacter();							return true;						} else if ( this.isDecimal ) {							//System.out.println("handling key for DECIMAL TextField");							if (currentLength < this.maxSize 									&& ( keyCode == Canvas.KEY_POUND || keyCode == Canvas.KEY_STAR )									&& (this.text.indexOf( Locale.DECIMAL_SEPARATOR) == -1)									) 							{																this.caretChar = Locale.DECIMAL_SEPARATOR;								//#ifdef polish.css.font-bitmap									if (this.bitMapFont != null) {										this.caretViewer = this.bitMapFont.getViewer("" + Locale.DECIMAL_SEPARATOR);									}								//#endif								insertCharacter();								return true;															}						}											}					if ( this.inputMode != MODE_NUMBERS 							&& !this.isUneditable							&& currentLength < this.maxSize 							&& ((keyCode >= Canvas.KEY_NUM0 							&& keyCode <= Canvas.KEY_NUM9)							|| (keyCode == Canvas.KEY_POUND ) 							|| (keyCode == Canvas.KEY_STAR )) ) 					{							String alphabet;						if (keyCode == Canvas.KEY_POUND) {							alphabet = charactersKeyPound;						} else if (keyCode == Canvas.KEY_STAR) {							alphabet = charactersKeyStar;						} else {							alphabet = CHARACTERS[ keyCode - Canvas.KEY_NUM0 ];						}						if (alphabet == null || (alphabet.length() == 0)) {							return false;						}						this.lastInputTime = System.currentTimeMillis();						char newCharacter;						int alphabetLength = alphabet.length();						if (keyCode == this.lastKey && (this.caretChar != this.editingCaretChar)) {							this.characterIndex++;							if (this.characterIndex >= alphabetLength) {								this.characterIndex = 0;							}						} else {							// insert the last character into the text:							if (this.caretChar != this.editingCaretChar) {								insertCharacter();							}							this.characterIndex = 0;							this.lastKey = keyCode;						}						newCharacter = alphabet.charAt( this.characterIndex );						if ( this.inputMode == MODE_UPPERCASE 								|| this.nextCharUppercase ) 						{							newCharacter = Character.toUpperCase(newCharacter);						}						//#ifdef polish.css.font-bitmap						if (this.bitMapFont != null) {							this.caretViewer = this.bitMapFont.getViewer("" + newCharacter);						} else {						//#endif							this.caretWidth = this.font.charWidth( newCharacter );						//#ifdef polish.css.font-bitmap						}						//#endif						this.caretChar = newCharacter;						if (alphabetLength == 1) {							insertCharacter();						}						return true;					}					boolean characterInserted = false;					char character = this.caretChar;					// allow backspace:					if ( currentLength > 0 ) {						if (this.isUneditable) {							return false;						}						//#ifdef polish.key.ClearKey:defined							//#= if (keyCode == ${polish.key.ClearKey}) {						//#else							if ( keyCode == -8 ) {						//#endif							//System.out.println("backspace");							return deleteCurrentChar();						}					}									if (this.caretChar != this.editingCaretChar) {						insertCharacter();						characterInserted = true;					}										// navigate the caret:					if (this.text == null) {						return false;					}					if (gameAction == Canvas.UP) {						//#ifdef polish.css.font-bitmap							if (this.bitMapFontViewer != null) {								// a bitmap-font is used								return false;							}						//#endif						// this TextField has a normal font:						if (this.caretRow ==  0) {							return false;						} 						// restore the text-line:						this.caretRow--;						this.caretY -= this.rowHeight;						this.internalY = this.caretY;						String fullLine = this.realTextLines[ this.caretRow ];						int previousCaretRowFirstLength = this.caretColumn;						setCaretRow(fullLine, this.caretColumn );						this.caretPosition -= previousCaretRowFirstLength + (this.originalRowText.length() - this.caretColumn);						this.internalX = 0;						this.internalY = this.caretRow * this.rowHeight;						return true;					} else if (gameAction == Canvas.DOWN) {						//#ifdef polish.css.font-bitmap							if (this.bitMapFontViewer != null) {								// a bitmap-font is used								return false;							}						//#endif						if (this.textLines == null || this.caretRow >= this.textLines.length - 1) {							return false;						} 									String lastLine = this.originalRowText;						int lastLineLength = lastLine.length();						if (characterInserted) {							lastLineLength++;						}						this.caretRow++;							this.caretY += this.rowHeight;						this.internalY = this.caretY;						int lastCaretRowLastPartLength = lastLineLength - this.caretColumn;						String nextLine = this.realTextLines[ this.caretRow ];						setCaretRow( nextLine, this.caretColumn );						this.caretPosition += (lastCaretRowLastPartLength + this.caretColumn );						this.internalY = this.caretRow * this.rowHeight;						return true;					} else if (this.isUneditable) {						return false;					} else if (gameAction == Canvas.LEFT) {						//#ifdef polish.css.font-bitmap							if (this.bitMapFontViewer != null) {								// a bitmap-font is used								// delete last character:								return deleteCurrentChar();							}						//#endif						if (this.caretColumn > 0) {							this.caretPosition--;							this.caretColumn--;							setCaretRow( this.originalRowText, this.caretColumn );							return true;						} else if ( this.caretRow > 0) {							// this is just a visual line-break:							//this.caretPosition--;							this.caretRow--;							String prevLine = this.realTextLines[ this.caretRow ];							setCaretRow(prevLine, prevLine.length() );							//System.out.println(this + ".handleKeyPressed()/font4: caretX=" + this.caretX);							this.caretY -= this.rowHeight;							this.internalY = this.caretY;							return true;						}					} else if ( gameAction == Canvas.RIGHT ) {						//#ifdef polish.debug.debug						if (this.isPassword) {							//#debug							System.out.println("originalRowText=" + this.originalRowText );						}						//#endif						if (characterInserted) {							//System.out.println("right but character inserted");							return true;						}						//#ifdef polish.css.font-bitmap							if (this.bitMapFontViewer != null) {								// a bitmap-font is used								return false;							}						//#endif						if (this.caretColumn < this.originalRowText.length() ) {							//System.out.println("right not in last column");							this.caretColumn++;							this.caretPosition++;							setCaretRow( this.originalRowText, this.caretColumn );							return true;						} else if (this.caretRow < this.realTextLines.length - 1) {							//System.out.println("right in not the last row");							this.caretRow++;							this.originalRowText = this.realTextLines[ this.caretRow ];							if (characterInserted) {								this.caretX = this.font.charWidth(character);								//System.out.println(this + ".handleKeyPressed()/font6: caretX=" + this.caretX);								this.caretColumn = 1;							} else {								setCaretRow( this.originalRowText, 0 );							}							this.caretY += this.rowHeight;							this.internalY = this.caretY;							return true;						} else if (characterInserted) {							//System.out.println("right after character insertion");							// a character has been inserted at the last column of the last row:							this.caretX += this.caretWidth;							this.caretRowFirstPart += character;							this.caretColumn++;							this.caretPosition++;							return true;						}					}					if (true) {						return false;					}					}				//#endif		//#if tmp.allowDirectInput			//# }		//#endif		//#ifndef polish.hasPointerEvents			String currentText = this.isPassword ? this.passwordText : this.text;			if (this.enableDirectInput) {				int currentLength = (this.text == null ? 0 : this.text.length());				if (currentLength < this.maxSize && 						keyCode >= Canvas.KEY_NUM0 && 						keyCode <= Canvas.KEY_NUM9) 				{						String newText = (currentText == null ? "" : currentText ) + (keyCode - 48);					setString( newText );					if (getScreen() instanceof Form) {						notifyStateChanged();					}					return true;				}				if (currentLength > 0) {					//#ifdef polish.key.ClearKey:defined						//#= if ((keyCode == ${polish.key.ClearKey}) || (gameAction == Canvas.LEFT)) {					//#else						if (keyCode == -8 || gameAction == Canvas.LEFT) {											//#endif						setString( currentText.substring(0, currentLength - 1) );						if (getScreen() instanceof Form) {							notifyStateChanged();						}						return true;					}				}								return false;			}		//#endif		if ( (keyCode >= Canvas.KEY_NUM0 			&& keyCode <= Canvas.KEY_NUM9)			//#ifdef polish.key.ClearKey:defined				//#= || (keyCode == ${polish.key.ClearKey})			//#else				|| (keyCode == -8)			//#endif			|| (gameAction == Canvas.FIRE ) )		{				//#if !(polish.blackberry || tmp.forceDirectInput)				showTextBox();			//#endif			return true;		} else {			return false;		}	}