/// <summary>
        /// Triggered when a widget is actuated. Call this in the OnWidgetActuated
        /// function in the Alphabet scanner.
        /// </summary>
        /// <param name="widget">widget that was actuated</param>
        /// <param name="handled">set to true if handled</param>
        public virtual void OnWidgetActuated(Widget widget, ref bool handled)
        {
            if (widget is WordListItemWidget)
            {
                _form.Invoke(new MethodInvoker(delegate
                {
                    Log.Debug("wordListItemName : " + widget.Name);
                    var item = widget as WordListItemWidget;
                    Log.Debug("Value: " + item.Value);
                    var wordSelected = item.Value.Trim();

                    if (!String.IsNullOrEmpty(wordSelected))
                    {
                        KeyStateTracker.ClearAlt();
                        KeyStateTracker.ClearCtrl();

                        _scannerCommon.AutoCompleteWord(wordSelected);
                        AuditLog.Audit(new AuditEventAutoComplete(widget.Name));
                    }
                }));
                handled = true;
            }
            else
            {
                handled = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// A key up to the corresponding keydown event was detected.  Notify callers
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void KeyboardHook_KeyUp(object sender, KeyEventArgs e)
        {
            if (actuatorState != State.Running)
            {
                return;
            }

            var s = String.Format("Keyup{0}.  Alt: {1} Ctrl: {2}", e.KeyCode, e.Alt, e.Control);

            Log.Debug(s);

            KeyStateTracker.KeyUp(e.KeyCode);

            var actuatorSwitch = findActuatorSwitch(e.KeyCode.ToString());

            if (actuatorSwitch != null)
            {
                e.Handled                 = true;
                actuatorSwitch.Action     = SwitchAction.Up;
                actuatorSwitch.Confidence = 100;
                OnSwitchDeactivated(actuatorSwitch);
            }
            else
            {
                if (EvtKeyUp != null)
                {
                    EvtKeyUp(this, e);
                }
            }
        }
Esempio n. 3
0
            /// <summary>
            /// Executes the command
            /// </summary>
            /// <param name="handled">set to true if handled</param>
            /// <returns>true</returns>
            public override bool Execute(ref bool handled)
            {
                handled = true;

                switch (Command)
                {
                case "CmdFunctionKey":
                    if (KeyStateTracker.IsFuncOn())
                    {
                        KeyStateTracker.ClearFunc();
                    }
                    else
                    {
                        KeyStateTracker.FuncTriggered();
                    }

                    break;

                case "CmdNumberPeriod":
                    Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), '.');
                    break;

                case "CmdNumberComma":
                    Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), ',');
                    break;

                default:
                    handled = false;
                    break;
                }

                return(true);
            }
Esempio n. 4
0
        /// <summary>
        /// Inserts the word at the specified offset
        /// </summary>
        /// <param name="offset">Where to insert the word</param>
        /// <param name="word">The word to insert</param>
        public virtual void Insert(int offset, String word)
        {
            try
            {
                AgentManager.Instance.TextChangedNotifications.Hold();

                int caretPos = GetCaretPos();
                if (caretPos != offset)
                {
                    SetCaretPos(offset);
                }
                else if (IsTextSelected())
                {
                    Keyboard.Send(Keys.Delete);
                }

                if (KeyStateTracker.IsCapsLockOn())
                {
                    word = word.ToLower();
                }

                sendWait(word);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            finally
            {
                AgentManager.Instance.TextChangedNotifications.Release();
            }
        }
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="handled">set to true if the command was handled</param>
        /// <returns>true on success</returns>
        public override bool Execute(ref bool handled)
        {
            handled = true;

            switch (Command)
            {
            case "CmdShiftKey":
                KeyStateTracker.KeyTriggered(Keys.LShiftKey);
                break;

            case "CmdCtrlKey":
                KeyStateTracker.KeyTriggered(Keys.LControlKey);
                break;

            case "CmdAltKey":
                KeyStateTracker.KeyTriggered(Keys.LMenu);
                break;

            default:
                handled = false;
                break;
            }

            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// Executes the command
        /// </summary>
        /// <param name="handled">set to true if the command was handled</param>
        /// <returns>true on success</returns>
        public override bool Execute(ref bool handled)
        {
            handled = true;

            switch (Command)
            {
            case "CmdCapsLock":
                Context.AppAgentMgr.Keyboard.Send(Keys.CapsLock);
                break;

            case "CmdNumLock":
                Context.AppAgentMgr.Keyboard.Send(Keys.NumLock);
                break;

            case "CmdScrollLock":
                Context.AppAgentMgr.Keyboard.Send(Keys.Scroll);
                break;

            case "CmdEnterKey":
                Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), '\n');
                KeyStateTracker.KeyTriggered('\n');
                break;
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Handles operations after a word has been autocompleted
        /// </summary>
        private void postAutoCompleteWord()
        {
            try
            {
                using (AgentContext context = Context.AppAgentMgr.ActiveContext())
                {
                    int caretPos = context.TextAgent().GetCaretPos();
                    if (caretPos > 0)
                    {
                        char charAtCaret;
                        bool retVal = context.TextAgent().GetCharAtCaret(out charAtCaret);

                        Log.Debug("charAtCaret is " + Convert.ToInt32(charAtCaret));
                        if (!retVal || charAtCaret == 0x0D || !Char.IsWhiteSpace(charAtCaret))
                        {
                            Log.Debug("Sending space suffix... caretpos is " + context.TextAgent().GetCaretPos());
                            Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), ' ');
                            Log.Debug("Done sending space suffix caretPos is " + context.TextAgent().GetCaretPos());
                            KeyStateTracker.KeyTriggered(' ');
                        }
                        else if (Char.IsWhiteSpace(charAtCaret))
                        {
                            SendKeys.SendWait("{DELETE}");
                            SendKeys.SendWait(charAtCaret.ToString());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Handles actuation of a button representing an alphanumeric character
        /// </summary>
        public void HandleAlphaNumericChar(ArrayList modifiers, char inputChar)
        {
            Context.AppAgentMgr.Keyboard.Send((modifiers != null) ? modifiers.Cast <Keys>().ToList() : KeyStateTracker.GetExtendedKeys(), inputChar);

            KeyStateTracker.KeyTriggered(inputChar);

            _lastAction = LastAction.AlphaNumeric;
        }
Esempio n. 9
0
        /// <summary>
        /// Handles actuation of a button representing an alphanumeric character
        /// </summary>
        /// <param name="inputChar">char to send</param>
        public void HandleAlphaNumericChar(char inputChar)
        {
            Context.AppAgentMgr.Keyboard.Send(inputChar);

            KeyStateTracker.KeyTriggered(inputChar);

            _lastAction = LastAction.AlphaNumeric;
        }
Esempio n. 10
0
        /// <summary>
        /// A keydown event was detected.  Check if this is one of the keys
        /// we are interested in.  The valid keys are defined as the 'source'
        /// attribute in a switch object
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">args</param>
        private void KeyboardHook_KeyDown(object sender, KeyEventArgs e)
        {
            if (actuatorState != State.Running)
            {
                return;
            }

            var s = String.Format("Keydown {0}.  Alt: {1} Ctrl: {2}", e.KeyCode, e.Alt, e.Control);

            Log.Debug(s);

            // check if this is one of the keys we recognize.  If so, trigger
            // a switch-activated event
            var actuatorSwitch = findActuatorSwitch(e.KeyCode.ToString());

            if (actuatorSwitch != null)
            {
                e.Handled                 = true;
                actuatorSwitch.Action     = SwitchAction.Down;
                actuatorSwitch.Confidence = 100;
                OnSwitchActivated(actuatorSwitch);
            }
            else
            {
                KeyStateTracker.KeyDown(e.KeyCode);

                // Get the status of ctrl, shift and alt keys from
                // the tracker.  Then format the final key. For
                // eg:  Ctrl+Alt+T
                string hotKey = KeyStateTracker.GetKeyPressedStatus();
                if (String.IsNullOrEmpty(hotKey))
                {
                    hotKey = e.KeyCode.ToString();
                }
                else
                {
                    hotKey += "+" + e.KeyCode.ToString();
                }

                Log.Debug("KeyStateTracker.KeyString: " + hotKey);

                // check which switch handles this hotkey and trigger it
                actuatorSwitch = findActuatorSwitch(hotKey);
                if (actuatorSwitch != null)
                {
                    actuatorSwitch.Action     = SwitchAction.Trigger;
                    actuatorSwitch.Confidence = 100;
                    OnSwitchTriggered(actuatorSwitch);
                }
                else
                {
                    if (EvtKeyDown != null)
                    {
                        EvtKeyDown(this, e);
                    }
                }
            }
        }
Esempio n. 11
0
 /// <summary>
 /// Navigates to the previous line in the text control
 /// </summary>
 private void handleGoToPrevLine()
 {
     if (_selectMode)
     {
         AgentManager.Instance.Keyboard.Send(Keys.LShiftKey, Keys.Up);
     }
     else
     {
         AgentManager.Instance.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), Keys.Up);
         KeyStateTracker.KeyTriggered(Keys.Up);
     }
 }
Esempio n. 12
0
 /// <summary>
 /// Clears the text in the talk window
 /// </summary>
 public void Clear()
 {
     if (_talkWindow != null && Windows.GetVisible(_talkWindowForm))
     {
         KeyStateTracker.ClearAll();
         _talkWindow.Clear();
         AuditLog.Audit(new AuditEventTalkWindow("clear"));
         if (EvtTalkWindowCleared != null)
         {
             EvtTalkWindowCleared(this, EventArgs.Empty);
         }
     }
 }
Esempio n. 13
0
        /// <summary>
        /// Updates the control that displays the status of the
        /// Function key.
        /// </summary>
        public void UpdateFuncStatus()
        {
            if (_statusBar != null && _statusBar.FuncStatus != null)
            {
                String label = String.Empty;
                if (KeyStateTracker.IsFuncOn())
                {
                    label = "f";
                }

                Windows.SetText(_statusBar.FuncStatus, label);
            }
        }
Esempio n. 14
0
        private void autoComplete(WordListItemWidget wordListWidget)
        {
            Log.Debug("wordListItemName : " + wordListWidget.Name + ", value: " + wordListWidget.Value);

            var wordSelected = wordListWidget.Value.Trim();

            if (!String.IsNullOrEmpty(wordSelected))
            {
                KeyStateTracker.ClearAlt();
                KeyStateTracker.ClearCtrl();

                _scannerCommon.AutoCompleteWord(wordSelected);
                AuditLog.Audit(new AuditEventAutoComplete(wordListWidget.Name));
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Turns off the select mode.
        /// </summary>
        private void turnOffSelectMode()
        {
            KeyStateTracker.ClearAll();

            try
            {
                using (AgentContext context = Context.AppAgentMgr.ActiveContext())
                {
                    context.TextAgent().SetSelectMode(false);
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// If the sticky shift is turned on, turn on select mode. If select
 /// mode is on, text is automatically selected as the user moves
 /// the cursor.
 /// </summary>
 private void turnOnSelectModeIfStickyShiftEnabled()
 {
     try
     {
         if (KeyStateTracker.IsStickyShiftOn())
         {
             using (AgentContext context = Context.AppAgentMgr.ActiveContext())
             {
                 context.TextAgent().SetSelectMode(true);
             }
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
Esempio n. 17
0
        protected bool sendFunctionKey(String keyString)
        {
            bool retVal = true;

            try
            {
                Keys key = (Keys)Enum.Parse(typeof(Keys), keyString, true);
                Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), key);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
                retVal = false;
            }

            return(retVal);
        }
Esempio n. 18
0
        /// <summary>
        /// Updates the control that displays the status of the
        /// shift key.
        /// </summary>
        public void UpdateShiftStatus()
        {
            if (_statusBar != null && _statusBar.ShiftStatus != null)
            {
                String label = String.Empty;
                if (KeyStateTracker.IsStickyShiftOn())
                {
                    label = "CAPS";
                }
                else if (KeyStateTracker.IsShiftOn())
                {
                    label = "SHIFT";
                }

                setText(_statusBar.ShiftStatus, label);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Updates the control that displays the status of the
        /// shift key.
        /// </summary>
        public void UpdateShiftStatus()
        {
            if (_statusBar != null && _statusBar.ShiftStatus != null)
            {
                String label = String.Empty;
                if (KeyStateTracker.IsStickyShiftOn())
                {
                    label = "a";
                }
                else if (KeyStateTracker.IsShiftOn())
                {
                    label = "b";
                }

                Windows.SetText(_statusBar.ShiftStatus, label);
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Updates the control that displays the status of the
        /// Alt key.
        /// </summary>
        public void UpdateAltStatus()
        {
            if (_statusBar != null && _statusBar.AltStatus != null)
            {
                String label = String.Empty;
                if (KeyStateTracker.IsStickyAltOn())
                {
                    label = "ALT LOCK";
                }
                else if (KeyStateTracker.IsAltOn())
                {
                    label = "ALT";
                }

                setText(_statusBar.AltStatus, label);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Updates the control that displays the status of the
        /// Ctrl key.
        /// </summary>
        public void UpdateCtrlStatus()
        {
            if (_statusBar != null && _statusBar.CtrlStatus != null)
            {
                String label = String.Empty;
                if (KeyStateTracker.IsStickyCtrlOn())
                {
                    label = "CTRL LOCK";
                }
                else if (KeyStateTracker.IsCtrlOn())
                {
                    label = "CTRL";
                }

                setText(_statusBar.CtrlStatus, label);
            }
        }
Esempio n. 22
0
 /// <summary>
 /// Navigates to the previous page in the text control
 /// </summary>
 private void handleGoToPrevPage()
 {
     if (_selectMode)
     {
         if (KeyStateTracker.IsCtrlOn())
         {
             AgentManager.Instance.Keyboard.Send(Keys.LControlKey, Keys.LShiftKey, Keys.PageUp);
         }
         else
         {
             AgentManager.Instance.Keyboard.Send(Keys.LShiftKey, Keys.PageUp);
         }
     }
     else
     {
         AgentManager.Instance.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), Keys.PageUp);
         KeyStateTracker.KeyTriggered(Keys.PageUp);
     }
 }
Esempio n. 23
0
            /// <summary>
            /// Executes the command
            /// </summary>
            /// <param name="handled">true if handled</param>
            /// <returns>true on success</returns>
            public override bool Execute(ref bool handled)
            {
                var form = Dispatcher.Scanner.Form as PunctuationsScanner;

                switch (Command)
                {
                case "1":
                case "2":
                case "3":
                case "4":
                case "5":
                case "6":
                case "7":
                case "8":
                case "9":
                case "0":
                    if (KeyStateTracker.IsFuncOn())
                    {
                        sendFunctionKey("F" + Command);

                        KeyStateTracker.ClearFunc();
                        KeyStateTracker.ClearShift();
                        KeyStateTracker.ClearAlt();
                        KeyStateTracker.ClearCtrl();
                    }
                    else
                    {
                        if (form._scannerCommon.ActuatedWidget != null)
                        {
                            form._scannerCommon.ActuateButton(form._scannerCommon.ActuatedWidget, Command[0]);
                        }
                    }

                    handled = true;
                    break;

                default:
                    handled = false;
                    break;
                }

                return(true);
            }
Esempio n. 24
0
        /// <summary>
        /// Handles acutation of a key such as a Function key.
        /// The 'value' parameter must be one of the Keys enum
        /// values.
        /// </summary>
        /// <param name="modifiers"></param>
        /// <param name="value">the key</param>
        public void HandleVirtualKey(ArrayList modifiers, String value)
        {
            _lastAction = LastAction.Unknown;

            try
            {
                Keys virtualKey = MapVirtualKey(value);
                if (virtualKey != Keys.None)
                {
                    Context.AppAgentMgr.Keyboard.Send((modifiers != null) ? modifiers.Cast <Keys>().ToList() : KeyStateTracker.GetExtendedKeys(), virtualKey);
                    //Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), virtualKey);
                    KeyStateTracker.KeyTriggered(virtualKey);
                }
            }
            catch
            {
                Log.Error("Invalid virtual key " + value.Substring(1));
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Navigates to the top of the text control
        /// </summary>
        private void handleGoToTop()
        {
            if (_selectMode)
            {
                AgentManager.Instance.Keyboard.Send(Keys.LControlKey, Keys.LShiftKey, Keys.Home);
            }
            else
            {
                if (KeyStateTracker.IsShiftOn())
                {
                    AgentManager.Instance.Keyboard.Send(Keys.LShiftKey, Keys.LControlKey, Keys.Home);
                }
                else
                {
                    AgentManager.Instance.Keyboard.Send(Keys.LControlKey, Keys.Home);
                }

                KeyStateTracker.KeyTriggered(Keys.Home);
            }
        }
Esempio n. 26
0
 /// <summary>
 /// Some modifier key was pressed. Handled it.
 /// </summary>
 private void KeyStateTracker_EvtKeyStateChanged()
 {
     try
     {
         // turn off select mode.  If select mode is on,
         // as the user moves the cursor, ACAT selects
         // text in the target window
         if (!KeyStateTracker.IsShiftOn())
         {
             using (AgentContext context = Context.AppAgentMgr.ActiveContext())
             {
                 context.TextAgent().SetSelectMode(false);
             }
         }
     }
     catch (Exception ex)
     {
         Log.Exception(ex);
     }
 }
Esempio n. 27
0
        /// <summary>
        /// Replaces 'count' letters at 'offset' with the word
        /// </summary>
        /// <param name="offset">0 based starting offset</param>
        /// <param name="count">number of chars to replace</param>
        /// <param name="word">Word to insert at the 'offset'</param>
        public virtual void Replace(int offset, int count, String word)
        {
            Log.Debug("offset = " + offset + " count " + count + " word " + word);

            try
            {
                AgentManager.Instance.TextChangedNotifications.Hold();

                int caretPos = GetCaretPos();
                if (caretPos != offset + count)
                {
                    SetCaretPos(offset + count);
                }
                else if (IsTextSelected())
                {
                    Keyboard.Send(Keys.Delete);
                }

                Log.Debug("Sending back");

                SendKeys.SendWait("{BACKSPACE " + count + "}");

                if (KeyStateTracker.IsCapsLockOn())
                {
                    word = word.ToLower();
                }

                Log.Debug("Sending word " + word);

                sendWait(word);
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }
            finally
            {
                AgentManager.Instance.TextChangedNotifications.Release();
            }
        }
Esempio n. 28
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyStateTracker.Update();
            GamePadStateTracker.Update();

            if (KeyStateTracker.JustPressed(Keys.Escape))
            {
                Exit();
            }
            if (KeyStateTracker.IsAltEnterJustPressed)
            {
                resizer.ToggleBorderlessFullscreen();
            }
            if (Debugger.IsAttached && !graphics.IsFullScreen && KeyStateTracker.JustPressed(Keys.F5))
            {
                Debugger.Break();
            }

            scene.Update(gameTime);

            base.Update(gameTime);
        }
Esempio n. 29
0
        /// <summary>
        /// Handles actuation of a button representation a punctuation
        /// </summary>
        /// <param name="modifiers">Any modfiers (shift, alt, ctrl)</param>
        /// <param name="punctuation">the punctuation</param>
        /// <returns>true on success</returns>
        public bool HandlePunctuation(ArrayList modifiers, char punctuation)
        {
            Log.Debug();

            try
            {
                if (!isPunctuation(punctuation))
                {
                    return(false);
                }

                // turn off extended keys such as alt, ctrl.  This causes problems when space
                // is inserted after puncuation and alt+space causes the system menu to show up.

                KeyStateTracker.ClearAlt();
                KeyStateTracker.ClearCtrl();
                KeyStateTracker.ClearFunc();

                using (AgentContext context = Context.AppAgentMgr.ActiveContext())
                {
                    int offset;
                    int count;

                    // delete any spaces before the punctuation
                    context.TextAgent().GetPrecedingWhiteSpaces(out offset, out count);
                    Log.Debug("Preceding whitespace count: " + count);
                    if (count > 0)
                    {
                        Log.Debug("Deleting whitespaces from offset " + offset);
                        context.TextAgent().Delete(offset, count);
                    }

                    Log.Debug("Sending punctuation");
                    Context.AppAgentMgr.Keyboard.Send((modifiers != null) ? modifiers.Cast <Keys>().ToList() : KeyStateTracker.GetExtendedKeys(), punctuation);

                    // if this is a sentence terminator, add spaces
                    // after the punctuation.

                    if ("})]".LastIndexOf(punctuation) >= 0)
                    {
                        Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), ' ');
                    }
                    else if (TextUtils.IsTerminator(punctuation))
                    {
                        for (int ii = 0; ii < CoreGlobals.AppPreferences.SpacesAfterPunctuation; ii++)
                        {
                            Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), ' ');
                        }
                    }

                    // this is important.  The ACAT talk window caretpos doesn't update until this we exit
                    // this function.  DoEvents give a chance to the talk window to update its caret position.
                    //Application.DoEvents();

                    _autoCompleteCaretPos = context.TextAgent().GetCaretPos();
                    Log.Debug("after actuating, caretpos is " + _autoCompleteCaretPos);

                    KeyStateTracker.KeyTriggered(punctuation);

                    _lastAction = LastAction.Punctuation;
                }
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return(true);
        }
Esempio n. 30
0
 /// <summary>
 /// Deletes the previous char in the application text window
 /// </summary>
 public void DeletePreviousChar()
 {
     Context.AppAgentMgr.Keyboard.Send(KeyStateTracker.GetExtendedKeys(), '\b');
 }