예제 #1
0
        /// <summary>
        /// Sends a character to the terminal.
        /// This is used for special characters like F1, Tab, et cetera.
        /// </summary>
        /// <param name="key">The key to send.</param>
        public void SendKey(TnKey key)
        {
            try
            {
                if (this.emu.IsConnected)
                {
                    enterKeyPressed = key == TnKey.Enter;
                    textKeyPressed = false;

                    this.emu.SendKey(true, key, 2000);

                    if (key == TnKey.Tab || key == TnKey.BackTab)
                    {
                        UpdateCaretIndex();
                        //	this.Refresh();
                    }
                    else if (key == TnKey.Erase || key == TnKey.Delete)
                    {
                        this.Refresh();
                    }
                }
            }
            catch (TNHostException tnHostException)
            {
                log.Warn("Exceção TNHostException em terminal.SendKey", tnHostException);
            }
            catch (Exception e)
            {
                log.Error("Exceção não esperada em terminal.SendKey", e);
                emu_Disconnected(emu, e.Message);
            }
        }
        public async override Task RunCommand(object sender)
        {
            var engine = (IAutomationEngineInstance)sender;

            int mouseX = 0, mouseY = 0;

            if (!string.IsNullOrEmpty(v_XMousePosition))
            {
                mouseX = (int)await v_XMousePosition.EvaluateCode(engine);
            }

            if (!string.IsNullOrEmpty(v_YMousePosition))
            {
                mouseY = (int)await v_YMousePosition.EvaluateCode(engine);
            }

            var          vTimeout       = ((int)await v_Timeout.EvaluateCode(engine)) * 1000;
            OpenEmulator terminalObject = (OpenEmulator)((OBAppInstance)await v_InstanceName.EvaluateCode(engine)).Value;

            if (terminalObject.TN3270 == null || !terminalObject.TN3270.IsConnected)
            {
                throw new Exception($"Terminal Instance {v_InstanceName} is not connected.");
            }

            TnKey selectedKey = (TnKey)Enum.Parse(typeof(TnKey), v_TerminalKey);

            if (!string.IsNullOrEmpty(v_XMousePosition) && !string.IsNullOrEmpty(v_YMousePosition))
            {
                terminalObject.TN3270.SetCursor(mouseX, mouseY);
            }

            terminalObject.TN3270.SendKey(false, selectedKey, vTimeout);
            terminalObject.Redraw();
        }
예제 #3
0
 /// <summary>
 /// Sends a character to the terminal.
 /// This is used for special characters like F1, Tab, et cetera.
 /// </summary>
 /// <param name="key">The key to send.</param>
 public void SendKey(TnKey key)
 {
     this.emu.SendKey(true, key, 2000);
     if (key != TnKey.Tab && key != TnKey.BackTab)
     {
         this.Refresh();
     }
 }
예제 #4
0
 /// <summary>
 /// Sends a character to the terminal.
 /// This is used for special characters like F1, Tab, et cetera.
 /// </summary>
 /// <param name="key">The key to send.</param>
 public void SendKey(TnKey key)
 {
     try
     {
         this.emu.SendKey(true, key, 2000);
         this.UpdateCaretIndex();
         if (key != TnKey.Tab && key != TnKey.BackTab)
         {
         }
     }
     catch (Exception ex)
     {
         Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {ex.Message}", ex);
     }
 }
예제 #5
0
        public void SendKey(TnKey tnKey)
        {
            var keySent = Emulator3270.SendKey(true, tnKey, _emulatorConfig.TimeOut);

            if (keySent)
            {
                if (!Emulator3270.WaitForHostSettle(200, _emulatorConfig.TimeOut))
                {
                    RaiseException(new Exception("Timeout waitting for host to settle!"));
                }
            }
            else
            {
                RaiseException(new Exception("Timeout sending Key '" + tnKey.ToString() + "'"));
            }
        }
        public override void RunCommand(object sender)
        {
            var          engine         = (IAutomationEngineInstance)sender;
            var          mouseX         = v_XMousePosition.ConvertUserVariableToString(engine);
            var          mouseY         = v_YMousePosition.ConvertUserVariableToString(engine);
            var          vTimeout       = int.Parse(v_Timeout.ConvertUserVariableToString(engine)) * 1000;
            OpenEmulator terminalObject = (OpenEmulator)v_InstanceName.GetAppInstance(engine);

            if (terminalObject.TN3270 == null || !terminalObject.TN3270.IsConnected)
            {
                throw new Exception($"Terminal Instance {v_InstanceName} is not connected.");
            }

            TnKey selectedKey = (TnKey)Enum.Parse(typeof(TnKey), v_TerminalKey);

            if (!string.IsNullOrEmpty(mouseX) && !string.IsNullOrEmpty(mouseY))
            {
                terminalObject.TN3270.SetCursor(int.Parse(mouseX), int.Parse(mouseY));
            }

            terminalObject.TN3270.SendKey(false, selectedKey, vTimeout);
            terminalObject.Redraw();
        }
        private void SendKey_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TnKey key = (TnKey)Enum.Parse(typeof(TnKey), KeytoSend.SelectedValue.ToString());
                mDriver.MFE.SendKey(key);

                if (RecordBtn.IsChecked == true)
                {
                    if (mDriver.mBusinessFlow == null)
                    {
                        return;
                    }
                    ActMainframeSendKey AMSK = new ActMainframeSendKey();
                    AMSK.Description = ("Send " + key.ToString() + " Key to Mainframe ");
                    mDriver.mBusinessFlow.CurrentActivity.Acts.Add((Actions.Act)AMSK);
                }

                Refresh();
            }
            finally
            {
            }
        }
예제 #8
0
        /// <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);
        }
예제 #9
0
 protected virtual void SetKeyNavigate(TnKey key)
 {
     KeyNavigate = key;
 }
예제 #10
0
 protected virtual void SetKeyPreview(TnKey key)
 {
     KeyPreview = key;
 }
예제 #11
0
 protected virtual void SetKeyForward(TnKey key)
 {
     KeyForward = key;
 }
예제 #12
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (TN3270.IsConnected)
            {
                if (TerminalKeys.Open3270TerminalKeysDict.ContainsKey(e.KeyCode))
                {
                    TnKey sendKey = TerminalKeys.Open3270TerminalKeysDict[e.KeyCode];
                    TN3270.SendKey(false, sendKey, 2000);
                }
                else if (e.KeyCode == Keys.ShiftKey)
                {
                    return;
                }
                else
                {
                    bool shift = false;

                    var character = (char)e.KeyCode;

                    if (GlobalHook.IsKeyDown(Keys.ShiftKey))
                    {
                        if (GlobalHook.IsKeyToggled(Keys.Capital))
                        {
                            if (char.IsLetter(character))
                            {
                                shift = false;
                            }
                            else
                            {
                                shift = true;
                            }
                        }
                        else
                        {
                            shift = true;
                        }
                    }
                    else
                    {
                        if (GlobalHook.IsKeyToggled(Keys.Capital))
                        {
                            if (char.IsLetter(character))
                            {
                                shift = true;
                            }
                        }
                        else
                        {
                            shift = false;
                        }
                    }

                    var buf           = new StringBuilder(256);
                    var keyboardState = new byte[256];

                    if (shift)
                    {
                        keyboardState[(int)Keys.ShiftKey] = 0xff;
                    }

                    GlobalHook.ToUnicode((uint)e.KeyCode, 0, keyboardState, buf, 256, 0);
                    var selectedKey = buf.ToString();
                    TN3270.SetText(selectedKey);
                }
                Redraw();
            }
            e.Handled = true;
        }