if (screenFields.getCurrentField().startPos() == lastPos) displayError(ERR_CURSOR_PROTECTED);  else { screenFields.getCurrentField().getKeyPos(lastPos); screenFields.getCurrentField().changePos(-1); resetDirty(screenFields.getCurrentField().getCurrentPos()); shiftLeft(screenFields.getCurrentField().getCurrentPos()); updateDirty(); screenFields.setCurrentFieldMDT();  simulated = true; } } else { displayError(ERR_CURSOR_PROTECTED);  } break; case BACK_TAB:  if (screenFields.getCurrentField() != null && screenFields.isCurrentFieldHighlightedEntry()) { resetDirty(screenFields.getCurrentField().startPos); gotoFieldPrev(); updateDirty(); } else gotoFieldPrev();  if (screenFields.isCurrentFieldContinued()) { do { gotoFieldPrev(); } while (screenFields.isCurrentFieldContinuedMiddle() || screenFields.isCurrentFieldContinuedLast()); } isInField(lastPos); simulated = true; break; case UP: case MARK_UP: process_XY(lastPos - numCols); simulated = true; break; case DOWN: case MARK_DOWN: process_XY(lastPos + numCols); simulated = true; break; case LEFT: case MARK_LEFT:  process_XY(lastPos - 1); simulated = true; break; case RIGHT: case MARK_RIGHT: process_XY(lastPos + 1); simulated = true; break; case NEXTWORD: gotoNextWord(); simulated = true; break; case PREVWORD: gotoPrevWord(); simulated = true; break; case DELETE: if (screenFields.getCurrentField() != null && screenFields.withinCurrentField(lastPos) && !screenFields.isCurrentFieldBypassField()) {  resetDirty(lastPos); screenFields.getCurrentField().getKeyPos(lastPos); shiftLeft(screenFields.getCurrentFieldPos()); screenFields.setCurrentFieldMDT(); updateDirty(); simulated = true; } else { displayError(ERR_CURSOR_PROTECTED); }  break; case TAB:  if (screenFields.getCurrentField() != null && !screenFields.isCurrentFieldContinued()) { if (screenFields.isCurrentFieldHighlightedEntry()) { resetDirty(screenFields.getCurrentField().startPos); gotoFieldNext(); updateDirty(); } else gotoFieldNext(); } else { do { gotoFieldNext(); } while (screenFields.getCurrentField() != null && (screenFields.isCurrentFieldContinuedMiddle() || screenFields .isCurrentFieldContinuedLast())); }  isInField(lastPos); simulated = true;  break; case EOF: if (screenFields.getCurrentField() != null && screenFields.withinCurrentField(lastPos) && !screenFields.isCurrentFieldBypassField()) { int where = endOfField(screenFields.getCurrentField() .startPos(), true); if (where > 0) { setCursor((where / numCols) + 1, (where % numCols) + 1); } simulated = true; } else { displayError(ERR_CURSOR_PROTECTED); } resetDirty(lastPos);  break; case ERASE_EOF: if (screenFields.getCurrentField() != null && screenFields.withinCurrentField(lastPos) && !screenFields.isCurrentFieldBypassField()) {  int where = lastPos; resetDirty(lastPos); if (fieldExit()) { screenFields.setCurrentFieldMDT(); if (!screenFields.isCurrentFieldContinued()) { gotoFieldNext(); } else { do { gotoFieldNext(); if (screenFields.isCurrentFieldContinued()) fieldExit(); } while (screenFields.isCurrentFieldContinuedMiddle() || screenFields.isCurrentFieldContinuedLast());
advancePos();    if (lastPos == startPos) {    goto_XY(startPos);  break;  }
	protected boolean simulateMnemonic(int mnem) {		boolean simulated = false;		switch (mnem) {		case AID_CLEAR:		case AID_ENTER:		case AID_PF1:		case AID_PF2:		case AID_PF3:		case AID_PF4:		case AID_PF5:		case AID_PF6:		case AID_PF7:		case AID_PF8:		case AID_PF9:		case AID_PF10:		case AID_PF11:		case AID_PF12:		case AID_PF13:		case AID_PF14:		case AID_PF15:		case AID_PF16:		case AID_PF17:		case AID_PF18:		case AID_PF19:		case AID_PF20:		case AID_PF21:		case AID_PF22:		case AID_PF23:		case AID_PF24:		case AID_ROLL_DOWN:		case AID_ROLL_UP:		case AID_ROLL_LEFT:		case AID_ROLL_RIGHT:			if (!screenFields.isCanSendAid()) {				displayError(ERR_ENTER_NO_ALLOWED);			} else				sendAid(mnem);			simulated = true;			break;		case AID_HELP:			sessionVT.sendHelpRequest();			simulated = true;			break;		case AID_PRINT:			sessionVT.hostPrint(1);			simulated = true;			break;		case BACK_SPACE:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				if (screenFields.getCurrentField().startPos() == lastPos)					displayError(ERR_CURSOR_PROTECTED);				else {					screenFields.getCurrentField().getKeyPos(lastPos);					screenFields.getCurrentField().changePos(-1);					resetDirty(screenFields.getCurrentField().getCurrentPos());					shiftLeft(screenFields.getCurrentField().getCurrentPos());					updateDirty();					screenFields.setCurrentFieldMDT();					simulated = true;				}			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case BACK_TAB:			if (screenFields.getCurrentField() != null					&& screenFields.isCurrentFieldHighlightedEntry()) {				resetDirty(screenFields.getCurrentField().startPos);				gotoFieldPrev();				updateDirty();			} else				gotoFieldPrev();			if (screenFields.isCurrentFieldContinued()) {				do {					gotoFieldPrev();				} while (screenFields.isCurrentFieldContinuedMiddle()						|| screenFields.isCurrentFieldContinuedLast());			}			isInField(lastPos);			simulated = true;			break;		case UP:		case MARK_UP:			process_XY(lastPos - numCols);			simulated = true;			break;		case DOWN:		case MARK_DOWN:			process_XY(lastPos + numCols);			simulated = true;			break;		case LEFT:		case MARK_LEFT:			process_XY(lastPos - 1);			simulated = true;			break;		case RIGHT:		case MARK_RIGHT:			process_XY(lastPos + 1);			simulated = true;			break;		case NEXTWORD:			gotoNextWord();			simulated = true;			break;		case PREVWORD:			gotoPrevWord();			simulated = true;			break;		case DELETE:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				resetDirty(lastPos);				screenFields.getCurrentField().getKeyPos(lastPos);				shiftLeft(screenFields.getCurrentFieldPos());				screenFields.setCurrentFieldMDT();				updateDirty();				simulated = true;			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case TAB:			if (screenFields.getCurrentField() != null					&& !screenFields.isCurrentFieldContinued()) {				if (screenFields.isCurrentFieldHighlightedEntry()) {					resetDirty(screenFields.getCurrentField().startPos);					gotoFieldNext();					updateDirty();				} else					gotoFieldNext();			} else {				do {					gotoFieldNext();				} while (screenFields.getCurrentField() != null						&& (screenFields.isCurrentFieldContinuedMiddle() || screenFields								.isCurrentFieldContinuedLast()));			}			isInField(lastPos);			simulated = true;			break;		case EOF:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int where = endOfField(screenFields.getCurrentField()						.startPos(), true);				if (where > 0) {					setCursor((where / numCols) + 1, (where % numCols) + 1);				}				simulated = true;			} else {				displayError(ERR_CURSOR_PROTECTED);			}			resetDirty(lastPos);			break;		case ERASE_EOF:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int where = lastPos;				resetDirty(lastPos);				if (fieldExit()) {					screenFields.setCurrentFieldMDT();					if (!screenFields.isCurrentFieldContinued()) {						gotoFieldNext();					} else {						do {							gotoFieldNext();							if (screenFields.isCurrentFieldContinued())								fieldExit();						} while (screenFields.isCurrentFieldContinuedMiddle()								|| screenFields.isCurrentFieldContinuedLast());					}				}				updateDirty();				goto_XY(where);				simulated = true;			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case ERASE_FIELD:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int where = lastPos;				lastPos = screenFields.getCurrentField().startPos();				resetDirty(lastPos);				if (fieldExit()) {					screenFields.setCurrentFieldMDT();					if (!screenFields.isCurrentFieldContinued()) {						gotoFieldNext();					} else {						do {							gotoFieldNext();							if (screenFields.isCurrentFieldContinued())								fieldExit();						} while (screenFields.isCurrentFieldContinuedMiddle()								|| screenFields.isCurrentFieldContinuedLast());					}				}				updateDirty();				goto_XY(where);				simulated = true;			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case INSERT:			// we toggle it			insertMode = insertMode ? false : true;			break;		case HOME:			// position to the home position set			if (lastPos + numCols + 1 != homePos) {				goto_XY(homePos - numCols - 1);				// now check if we are in a field				isInField(lastPos);			} else				gotoField(1);			break;		case KEYPAD_0:			simulated = simulateKeyStroke('0');			break;		case KEYPAD_1:			simulated = simulateKeyStroke('1');			break;		case KEYPAD_2:			simulated = simulateKeyStroke('2');			break;		case KEYPAD_3:			simulated = simulateKeyStroke('3');			break;		case KEYPAD_4:			simulated = simulateKeyStroke('4');			break;		case KEYPAD_5:			simulated = simulateKeyStroke('5');			break;		case KEYPAD_6:			simulated = simulateKeyStroke('6');			break;		case KEYPAD_7:			simulated = simulateKeyStroke('7');			break;		case KEYPAD_8:			simulated = simulateKeyStroke('8');			break;		case KEYPAD_9:			simulated = simulateKeyStroke('9');			break;		case KEYPAD_PERIOD:			simulated = simulateKeyStroke('.');			break;		case KEYPAD_COMMA:			simulated = simulateKeyStroke(',');			break;		case KEYPAD_MINUS:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int s = screenFields.getCurrentField().getFieldShift();				if (s == 3 || s == 5 || s == 7) {               planes.setChar(lastPos,'-');					resetDirty(lastPos);					advancePos();					if (fieldExit()) {						screenFields.setCurrentFieldMDT();						if (!screenFields.isCurrentFieldContinued()) {							gotoFieldNext();						} else {							do {								gotoFieldNext();							} while (screenFields									.isCurrentFieldContinuedMiddle()									|| screenFields											.isCurrentFieldContinuedLast());						}						simulated = true;						updateDirty();						if (screenFields.isCurrentFieldAutoEnter())							sendAid(AID_ENTER);					}				} else {					displayError(ERR_FIELD_MINUS);				}			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case FIELD_EXIT:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				resetDirty(lastPos);				if (fieldExit()) {					screenFields.setCurrentFieldMDT();					if (!screenFields.isCurrentFieldContinued()) {						gotoFieldNext();					} else {						do {							gotoFieldNext();							if (screenFields.isCurrentFieldContinued())								fieldExit();						} while (screenFields.isCurrentFieldContinuedMiddle()								|| screenFields.isCurrentFieldContinuedLast());					}				}				updateDirty();				simulated = true;				if (screenFields.isCurrentFieldAutoEnter())					sendAid(AID_ENTER);			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case FIELD_PLUS:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				resetDirty(lastPos);				if (fieldExit()) {					screenFields.setCurrentFieldMDT();					if (!screenFields.isCurrentFieldContinued()) {						gotoFieldNext();					} else {						do {							gotoFieldNext();						} while (screenFields.isCurrentFieldContinuedMiddle()								|| screenFields.isCurrentFieldContinuedLast());					}				}				updateDirty();				simulated = true;				if (screenFields.isCurrentFieldAutoEnter())					sendAid(AID_ENTER);			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case FIELD_MINUS:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int s = screenFields.getCurrentField().getFieldShift();				if (s == 3 || s == 5 || s == 7) {               planes.setChar(lastPos,'-');					resetDirty(lastPos);					advancePos();					if (fieldExit()) {						screenFields.setCurrentFieldMDT();						if (!screenFields.isCurrentFieldContinued()) {							gotoFieldNext();						} else {							do {								gotoFieldNext();							} while (screenFields									.isCurrentFieldContinuedMiddle()									|| screenFields											.isCurrentFieldContinuedLast());						}					}					updateDirty();					simulated = true;					if (screenFields.isCurrentFieldAutoEnter())						sendAid(AID_ENTER);				} else {					displayError(ERR_FIELD_MINUS);				}			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case BOF:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				int where = screenFields.getCurrentField().startPos();				if (where > 0) {					goto_XY(where);				}				simulated = true;			} else {				displayError(ERR_CURSOR_PROTECTED);			}			resetDirty(lastPos);			break;		case SYSREQ:			sessionVT.systemRequest();			simulated = true;			break;		case RESET:			if (isStatusErrorCode()) {				resetError();				isInField(lastPos);				updateDirty();			} else {				setPrehelpState(false, oia.isKeyBoardLocked(), false);			}			simulated = true;			break;		case ATTN:			sessionVT.sendAttentionKey();			simulated = true;			break;		case DUP_FIELD:			if (screenFields.getCurrentField() != null					&& screenFields.withinCurrentField(lastPos)					&& !screenFields.isCurrentFieldBypassField()) {				if (screenFields.isCurrentFieldDupEnabled()) {					resetDirty(lastPos);					screenFields.getCurrentField().setFieldChar(lastPos,							(char) 0x1C);					screenFields.setCurrentFieldMDT();					gotoFieldNext();					updateDirty();					simulated = true;				} else {					displayError(ERR_DUP_KEY_NOT_ALLOWED);				}			} else {				displayError(ERR_CURSOR_PROTECTED);			}			break;		case NEW_LINE:			if (screenFields.getSize() > 0) {				int startRow = getRow(lastPos) + 1;				int startPos = lastPos;				boolean isthere = false;				if (startRow == getRows())					startRow = 0;				setCursor(++startRow, 1);				if (!isInField() && screenFields.getCurrentField() != null						&& !screenFields.isCurrentFieldBypassField()) {					while (!isInField()							&& screenFields.getCurrentField() != null							&& !screenFields.isCurrentFieldBypassField()) {						// lets keep going						advancePos();						// Have we looped the screen?						if (lastPos == startPos) {							// if so then go back to starting point							goto_XY(startPos);							break;						}					}				}			}			simulated = true;			break;		default:			log.info(" Mnemonic not supported " + mnem);			break;		}		return simulated;	}