/// <summary> /// Sends the specified key stroke to the emulator. /// </summary> /// <param name="waitForScreenToUpdate"></param> /// <param name="key"></param> /// <param name="timeout"></param> /// <returns></returns> public bool SendKey(bool waitForScreenToUpdate, TnKey key, int timeout) { bool triggerSubmit = false; bool success = false; string command; //This is only used as a parameter for other methods when we're using function keys. //e.g. F1 yields a command of "PF" and a functionInteger of 1. int functionInteger = -1; if (sout != null && Debug == true) { sout.WriteLine("SendKeyFromText(" + waitForScreenToUpdate + ", \"" + key.ToString() + "\", " + timeout + ")"); } if (currentConnection == null) { throw new TNHostException("TNEmulator is not connected", "There is no currently open TN3270 connection", null); } //Get the command name and accompanying int parameter, if applicable if (Constants.FunctionKeys.Contains(key)) { command = "PF"; functionInteger = Constants.FunctionKeyIntLUT[key]; } else if (Constants.AKeys.Contains(key)) { command = "PA"; functionInteger = Constants.FunctionKeyIntLUT[key]; } else { command = key.ToString(); } //Should this action be followed by a submit? triggerSubmit = this.Config.SubmitAllKeyboardCommands || this.currentConnection.KeyboardCommandCausesSubmit(command); if (triggerSubmit) { lock (this) { this.DisposeOfCurrentScreenXML(); currentScreenXML = null; if (sout != null && Debug) { sout.WriteLine("mre.Reset. Count was " + semaphore.Count); } // Clear to initial count (0) semaphore.Reset(); } } success = this.currentConnection.ExecuteAction(triggerSubmit, command, functionInteger); if (sout != null && Debug) { sout.WriteLine("SendKeyFromText - submit = " + triggerSubmit + " ok=" + success); } if (triggerSubmit && success) { // Wait for a valid screen to appear if (waitForScreenToUpdate) { success = this.Refresh(true, timeout); } else { success = true; } } return(success); }
/// <summary> /// Sends a key to the host. Key names are: /// Attn, Backspace,BackTab,CircumNot,Clear,CursorSelect,Delete,DeleteField, /// DeleteWord,Down,Dup,Enter,Erase,EraseEOF,EraseInput,FieldEnd, /// FieldMark,FieldExit,Home,Insert,Interrupt,Key,Left,Left2,Newline,NextWord, /// PAnn, PFnn, PreviousWord,Reset,Right,Right2,SysReq,Tab,Toggle,ToggleInsert,ToggleReverse,Up /// </summary> /// <param name="WaitForScreenToUpdate"></param> /// <param name="text">Key to send</param> /// <param name="timeout">Timeout in seconds</param> /// <returns></returns> public bool SendKeyFromText(bool WaitForScreenToUpdate, string text, int timeout) { if (sout != null && Debug == true) { sout.WriteLine("SendKeyFromText(" + WaitForScreenToUpdate + ", \"" + text + "\", " + timeout + ")"); } // if (currentConnection == null) { throw new TNHostException("TNEmulator is not connected", "There is no currently open TN3270 connection", null); } // if (text.Length < 2) { return(false); // no keys are less than 2 characters. } // bool submit = false; if (Config.SubmitAllKeyboardCommands) { submit = true; } else { if (text.Substring(0, 2) == "PF") { submit = this.currentConnection.KeyboardCommandCausesSubmit("PF", System.Convert.ToInt32(text.Substring(2, 2))); } else if (text.Substring(0, 2) == "PA") { submit = this.currentConnection.KeyboardCommandCausesSubmit("PA", System.Convert.ToInt32(text.Substring(2, 2))); } else { submit = this.currentConnection.KeyboardCommandCausesSubmit(text); } } bool ok = false; if (submit) { lock (this) { DisposeOfCurrentScreenXML(); _currentScreenXML = null; if (sout != null && Debug) { sout.WriteLine("mre.Reset. Count was " + mre.Count); } mre.Reset(); // clear to initial count (0) } // } // if (text.Substring(0, 2) == "PF") { ok = this.currentConnection.ExecuteAction(submit, "PF", System.Convert.ToInt32(text.Substring(2, 2))); } else if (text.Substring(0, 2) == "PA") { ok = this.currentConnection.ExecuteAction(submit, "PA", System.Convert.ToInt32(text.Substring(2, 2))); } else { ok = this.currentConnection.ExecuteAction(submit, text); } if (sout != null && Debug == true) { sout.WriteLine("SendKeyFromText - submit = " + submit + " ok=" + ok); } if (submit && ok) { // wait for a valid screen to appear if (WaitForScreenToUpdate) { return(Refresh(true, timeout)); } else { return(true); } } else { return(ok); } }