Пример #1
0
        public Context(string WindowName = null, string WindowDescription = null, Context ParentContext = null)
        {
            this.WindowName        = WindowName == null ? null : WindowName.ToLower();
            this.WindowDescription = WindowDescription == null ? null : WindowDescription.ToLower();
            this.ParentContext     = ParentContext;

            Base.AllContexts.Add(this);
        }
Пример #2
0
        public static KeyMap GetContextMap(Context context)
        {
            if (context == null) return null;

            if (Map.ContainsKey(context))
            {
                return Map[context];
            }
            else
            {
                return GetContextMap(context.ParentContext);
            }
        }
Пример #3
0
        public static void UsingContext(Context context, bool CopyParentContext = false)
        {
            CurrentContext = context;

            if (CopyParentContext)
            {
                if (!Map.ContainsKey(context))
                {
                    Map.Add(context, new KeyMap());
                }

                if (context.ParentContext != null)
                {
                    Map[context].Copy(Map[context.ParentContext]);
                }
            }
        }
Пример #4
0
        public void HookManager_KeyDown(object sender, KeyEventArgs e)
        {
            //Log(string.Format("{0}", e.KeyValue));

            try
            {
                if (Skip)
                {
                    if (DoLog) Log("Skip Down " + e.Key().ToString());
                    return;
                }

                if (PressedKeys.Count > 0)
                {
                    var Chord = PressedKeys.Aggregate("", (s, key) => s + key.Value + ',');
                    if (DoLog) Log(string.Format("Chord is {0} {1}.  {2} keys total.", Chord, e.Key().Value, PressedKeys.Count + 1));
                }

                // Shift-Shift = CapsLock
                if (CheckForShiftShift(e)) return;

                // Log event info
                if (DoLog) Log(string.Format("Window name is {0}", WindowFunctions.GetActiveWindowTitle()));
                if (DoLog) Log(string.Format("KeyDown {0} ({1}) {2}{3}{4}", e.KeyCode, (char)e.KeyValue,
                    Key.Shift.IsDown ? " Shift" : "",
                    Key.Alt.IsDown   ? " Alt"   : "",
                    Key.Ctrl.IsDown  ? " Ctrl" : ""));

                if (e.KeyCode == Keys.B)
                    Console.Write("");

                KeyMap CurrentMap = null;
                if (HoldContext == null)
                {
                    Ambiguous = false;

                    HoldContext = Base.ActiveContext;
                    CurrentMap = Base.ActiveContextMap;

                    Base.CurrentContext = HoldContext;
                }
                else
                {
                    if (DoLog) Log(string.Format("CurrentContext is {0}", HoldContext));

                    CurrentMap = Base.GetContextMap(HoldContext);

                    foreach (var k in PressedKeys)
                    {
                        if (CurrentMap == null) break;

                        if (CurrentMap.ContainsKey(k))
                        {
                            var result = CurrentMap[k];
                            if (result.MyMap != null)
                            {
                                CurrentMap = result.MyMap;
                            }
                            else
                            {
                                CurrentMap = null;
                                break;
                            }
                        }
                        else
                        {
                            CurrentMap = null;
                            break;
                        }
                    }
                }

                if (CurrentMap != null && CurrentMap.ContainsKey(e.Key()))
                {
                    var result = CurrentMap[e.Key()];
                    if (result.MyAction == null)
                    {
                        CurrentMap = result.MyMap;
                        PressedKeys.Add(e.Key());

                        Ambiguous = PressedKeys.Count == 1;
                    }
                    else
                    {
                        Skip = true;

                        if (DoLog) Log(string.Format("Action in {0}: {1}", HoldContext.WindowName, result.MyAction));
                        result.MyAction.Execute();

                        Skip = false;

                        Ambiguous = false;
                    }

                    Suppress(e);
                }
                else
                {
                    //SendAmbiguousKeys();
                    //Reset();
                }
            }
            catch (Exception exc)
            {
                Log(exc);
            }
        }
Пример #5
0
 public void Reset()
 {
     PressedKeys.Clear();
     HoldContext = null;
 }
Пример #6
0
 public Context(Context ParentContext)
     : this(null, null, ParentContext)
 {
 }
        public void Execute(Context context, ExecuteType type = ExecuteType.Press)
        {
            if (context == null) return;

            if (ContextualEvents.ContainsKey(context))
            {
                ContextualEvents[context](context, type);
            }
            else
            {
                Execute(context.ParentContext, type);
            }
        }