Exemplo n.º 1
0
        public static GesturesCollection LoadGestures()
        {
            GesturesCollection gestures = new GesturesCollection();
            Stream             stream   = null;

            try
            {
                stream = File.Open(Config.Default.FilesLocation + GESTURES, FileMode.Open);
                BinaryFormatter bFormatter = new BinaryFormatter();
                gestures = (GesturesCollection)bFormatter.Deserialize(stream);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                gestures.Add(MyGesture.GlobalGroup);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
            return(gestures);
        }
Exemplo n.º 2
0
        private GesturesCollection GetRecognizedGestures(string name)
        {
            GesturesCollection recognizedGestures = new GesturesCollection();

            m_hwndWindowToUse = GetWindowToUse(m_cursorPosition);
            IntPtr hwnd = m_hwndWindowToUse;// GetWindowToUse(m_cursorPosition); //m_hwndWndToUse;

            //if (Config.User.handleWndUnderCursor)
            //    hwnd = m_mouse.ActiveWindow;
            //else
            //    hwnd = m_hwndWndToUse;
            foreach (MyGesture gesture in learntGestures.MatchedGestures(name))
            {
                if (gesture.IsActive(hwnd))
                {
                    recognizedGestures.Add(gesture);
                    if (gesture.ExecutionType == ExecuteType.Implicit || gesture.IsImplicitOnly)
                    {
                        recognizedGestures.Clear();
                        recognizedGestures.Add(gesture);
                        break;
                    }
                }
            }
            return(recognizedGestures);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Analyze the drawn curve and find associated learnt one
        /// </summary>
        private void StartAnalyze()
        {
            //form_top.MakeNonTopMost();
            //if (cMS_MatchedGestures.Visible)
            //    form_top.CloseAndClearContextMenu(cMS_MatchedGestures);

            Debug.WriteLine("Thread StartAnalyze started");
            int approxPoints = Config.User.NnInputSize / 2 + 1;

            double[] nnInput = null;
            if (m_curve == null)
            {
                return;
            }
            else
            {
                //Get scaled input cannot last to long otherwise might be modified with new curve
                try { nnInput = m_curve.GetScaledInput(); }
                catch (Exception ex) { nnInput = null; }
            }
            m_curve = null;
            if (nnInput == null)
            {
                return;
            }

            double divergence;
            string nn_name = m_network.RecognizeCurve(nnInput, out divergence);

            m_threadID = Thread.CurrentThread.ManagedThreadId;
            GesturesCollection recognizedGestures = GetRecognizedGestures(nn_name);

            ExecuteRecognizedGestures(recognizedGestures);
        }
Exemplo n.º 4
0
        private void ShowToolTip(string name)
        {
            GesturesCollection recognizedGestures = GetRecognizedGestures(name);

            string msg = string.Empty;

            foreach (MyGesture ga in recognizedGestures)
            {
                //if (ga.ExecutionType == ExecuteType.Implicit)
                //{
                //    msg = ga.Caption + "\n";
                //    break;
                //}
                msg += (ga.Caption + "\n");
            }
            if (msg == string.Empty)
            {
                msg = Unknown_gesture;
            }
            else
            {
                msg = msg.Substring(0, msg.Length - 1);
            }
            form_top.ShowToolTip(msg);
        }
Exemplo n.º 5
0
        public static string CreateUniqueId(MyGesture gest, GesturesCollection gestures)
        {
            string name    = gest.Action.Name;
            int    postfix = 1;

            while (gestures[name + postfix.ToString()] != null)
            {
                postfix++;
            }
            return(name + postfix.ToString());
        }
Exemplo n.º 6
0
        void MyMouse_WheelBtnAction(MouseEventArgs trigger, ExtraMouseActions action)
        {
            Debug.WriteLine(string.Format("MyEngine: WheelBtnAction Trigger: {0} Action: {1}", trigger.Button, action));
            if (!m_wheelBtnUsed)
            {
                form_top.CloseContextMenu();
            }
            m_cursorPosition = trigger.Location;
            m_hwndForeWnd    = Win32.GetForegroundWindow();
            //m_hwndWndToUse = GetWindowToUse(trigger.Location);

            string name = WheelButton.GetName(trigger.Button);

            GesturesCollection recognizedGestures = GetRecognizedGestures(name);

            if (recognizedGestures.Count == 0)
            {
                return;
            }
            MyGesture gestToExecute = recognizedGestures[0];

            if (!m_wheelBtnUsed)
            {
                m_wheelBtnUsed = true;
                ExecuteImplicitOnlyAction(gestToExecute.Action, KeystrokesOptions.MouseAction.TriggerDown, true);
            }
            switch (action)
            {
            case ExtraMouseActions.WheelDown:
                ExecuteImplicitOnlyAction(gestToExecute.Action, KeystrokesOptions.MouseAction.WheelDown, false);
                break;

            case ExtraMouseActions.WheelUp:
                ExecuteImplicitOnlyAction(gestToExecute.Action, KeystrokesOptions.MouseAction.WheelUp, false);
                break;

            case ExtraMouseActions.None:
                ExecuteImplicitOnlyAction(gestToExecute.Action, KeystrokesOptions.MouseAction.TriggerUp, false);
                m_wheelBtnUsed = false;
                break;
            }
        }
Exemplo n.º 7
0
        public static void SaveGestures(GesturesCollection gestures)
        {
            Stream stream = null;

            try
            {
                stream = File.Open(Config.Default.FilesLocation + GESTURES, FileMode.Create);
                BinaryFormatter bFormatter = new BinaryFormatter();
                bFormatter.Serialize(stream, gestures);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Close();
                }
            }
        }
Exemplo n.º 8
0
        //void MyMouse_MouseBrowseWheel(ExtraMouseHook.WheelAction wheelAction)
        //{
        //    switch (wheelAction)
        //    {
        //        case WheelAction.Down:
        //            m_mouse.SimulateMouseAction(MouseAction.LeftDoubleClick);
        //            break;
        //        case WheelAction.Up:
        //            KeyInput.ExecuteKeyInput(AllKeys.KEY_BACK);
        //            break;
        //    }
        //}

        void MyMouse_DoubleBtnAction(MouseEventArgs trigger, MouseEventArgs modifier, bool notifyOnly)
        {
            Debug.WriteLine(string.Format("MyEngine: DoubleBtnAction {0}/{1} NotifyOnly: {2}", trigger.Button, modifier.Button, notifyOnly));
            form_top.CloseContextMenu();
            m_cursorPosition = modifier.Location;
            m_hwndForeWnd    = Win32.GetForegroundWindow();
            //m_hwndWndToUse = GetWindowToUse(modifier.Location);

            string name = DoubleButton.GetName(trigger.Button, modifier.Button);

            if (notifyOnly)
            {
                ShowToolTip(name);
            }
            else
            {
                //form_top.CloseContextMenu();
                GesturesCollection recognizedGestures = GetRecognizedGestures(name);
                if (recognizedGestures.Count == 0)
                {
                    return;
                }

                if (recognizedGestures.Count == 1 && recognizedGestures[0].IsImplicitOnly)
                {
                    MyGesture gestToExecute = recognizedGestures[0];
                    ExecuteImplicitOnlyAction(gestToExecute.Action, KeystrokesOptions.MouseAction.ModifierClick, true);
                }
                else
                {
                    m_dblBtnGesturesToExecute = recognizedGestures;
                    //ExecuteDblBtnGestures();
                    Thread threadExecuteDblBtnGestures = new Thread(new ThreadStart(ExecuteDblBtnGestures));
                    threadExecuteDblBtnGestures.Start();
                }
            }
        }
Exemplo n.º 9
0
        public Form_engine()
        {
            InitializeComponent();
            m_theForm   = this;
            m_trayIcons = new List <NotifyIcon>();
            //m_privateClipboards = new ReadOnlyCollection<ClipData>[ControlItems.UC_clipboard.CLIPS_COUNT];
            m_privateTextClipboards = new string[ControlItems.UC_clipboard.CLIPS_COUNT];

            // create directory for storing configuration and gestures if it doesn't exists
            // otherwise nothing will be saved
            if (!System.IO.Directory.Exists(Config.Default.FilesLocation))
            {
                try { System.IO.Directory.CreateDirectory(Config.Default.FilesLocation); }
                catch { }
            }

            m_gestures = FileOptions.LoadGestures();
            List <PrgNamePath> whiteList, blackList, finalList;

            FileOptions.LoadLists(out whiteList, out blackList, out finalList);

            m_engine = new MyEngine();
            m_engine.LearntGestures = m_gestures;
            m_engine.Network.Curves = m_gestures.GetCurves();
            m_engine.Network.CheckParams();
            m_engine.AppStateChanged += new MyEngine.DlgAppStateChanged(AppStateChanged);
            m_engine.FinalList        = finalList;
            m_engine.SetImageList();
            m_engine.ApplySettings();
            Microsoft.Win32.SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged);
            Microsoft.Win32.SystemEvents.PowerModeChanged       += new Microsoft.Win32.PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
            //RegistryEdit.SetWin7AntiBug();
            //RegistryEdit.RemWin7AntiBug();
            m_activeGestures = true;
            Translate();
        }
Exemplo n.º 10
0
        private void ExecuteRecognizedGestures(GesturesCollection recognizedGestures)
        {
            //form_top.ClearContextMenu();
            int       threadID = Thread.CurrentThread.ManagedThreadId;
            int       index    = 0;
            MyGesture gest;

            switch (recognizedGestures.Count)
            {
            case 0:
                // if curve wasnt recognize then hide form_transparent
                //form_top.MakeNonTopMost();
                break;

            case 1:
                gest = recognizedGestures[index];
                if (gest.ExecutionType == ExecuteType.Implicit || gest.ExecutionType == ExecuteType.ImplicitIfUnique)
                {
                    Debug.WriteLine("Execute : " + gest.ID);
                    switch (gest.Action.Name)
                    {
                    case TypeOfAction.SpecialOptions.SPECIAL_ZOOM:
                        //int area_width = Math.Abs(area_right - area_left);
                        //int area_height = Math.Abs(area_bottom - area_top);
                        //recognizedGestures[0].gAction.Details = string.Format("{0}:{1}:{2}:{3}", area_left, area_top, area_width, area_height);
                        gest.Action.Details = string.Format("{0}:{1}:{2}:{3}", 10, 10, 100, 100);
                        goto default;

                    //break;
                    case TypeOfAction.WindowOptions.WND_TRANSPARENT:
                    case TypeOfAction.VolumeOptions.VOLUME_SET:
                        ToolStripMenuItem[] items = tSMI_arrayMenu(gest);

                        if (threadID == m_threadID)
                        {
                            lock (this)
                            {
                                form_top.ClearContextMenu();
                            }
                        }
                        else
                        {
                            break;
                        }

                        for (int i = 0; i < items.Length; i++)
                        {
                            if (threadID == m_threadID)
                            {
                                lock (this)
                                {
                                    form_top.AddItemToCms(items[i]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        //foreach (ToolStripMenuItem item in items)
                        //    form_top.AddItemToCms(cMS_MatchedGestures, item);
                        if (threadID == m_threadID)
                        {
                            lock (this)
                            {
                                form_top.ShowContextMenu();
                            }
                        }
                        break;

                    default:
                        // gesture was recognized therefore hide the form_transparent
                        //form_top.MakeNonTopMost();

                        m_execute = gest;
                        //Thread threadExecuteAction = new Thread(new ThreadStart(ExecuteAction));
                        //threadExecuteAction.Name = "Execute Action";
                        //threadExecuteAction.Start();

                        // no need to do it in thread as it is already in one
                        ExecuteAction();
                        break;
                    }
                    break;
                }
                else
                {
                    goto default;
                }

            //break;
            default:
                if (threadID == m_threadID)
                {
                    lock (this)
                    {
                        form_top.ClearContextMenu();
                    }
                }

                for (int i = 0; i < recognizedGestures.Count; i++)
                {
                    gest = recognizedGestures[i];
                    if (gest.ExecutionType == ExecuteType.Implicit)
                    {
                        index = i;
                        goto case 1;
                    }
                    if (threadID == m_threadID)
                    {
                        lock (this)
                        {
                            switch (gest.Action.Name)
                            {
                            case TypeOfAction.WindowOptions.WND_TRANSPARENT:
                            case TypeOfAction.VolumeOptions.VOLUME_SET:
                                //case TypeOfAction.SpecialControl.SPECIAL_ZOOM:
                                //form_top.AddItemToCms(cMS_MatchedGestures, tSMI_dropDownMenu(gest));
                                form_top.AddItemToCms(tSMI_dropDownMenu(gest));
                                break;

                            default:
                                //ToolStripMenuItem item = new ToolStripMenuItem();
                                //item.Image = gest.ImageList.Images[gest.ID];
                                //item.Name = gest.ID;
                                //item.Text = gest.Caption;
                                //form_top.AddItemToCms(cMS_SameGestures, item);
                                //form_top.AddItemToCms(cMS_MatchedGestures, gest.ToToolStripMenuItem(m_imgListActions));
                                form_top.AddItemToCms(gest.ToToolStripMenuItem(m_imgListActions));
                                break;
                            }
                        }
                    }
                }
                if (threadID == m_threadID)
                {
                    lock (this)
                    {
                        form_top.ShowContextMenu();
                    }
                }

                break;
            }
        }