Example #1
0
            public override void txtInfo_MouseDown(object sender, MouseButtonEventArgs e)
            {
                if (focusChangedChild(txtInfo))
                {
                    e.Handled = true;
                    //var prev = txtInfo.Text;
                    //Model.Info = "<new key>";
                    txtInfo.Foreground = new SolidColorBrush(Colors.Orange);
                    Hook.OnKeyDelegate onD = (key) =>
                    {
                        Dispatcher.Invoke(() =>
                        {
                            txtInfo.Foreground = new SolidColorBrush(BLUE);
                            Model.Info         = key.ToString();
                            proposedKey        = key;
                            //Console.WriteLine("!");
                        });
                    };
                    Hook.OnKeyDelegate onU = (key) => { };
                    Hook.I().AddKeyHook(onD, onU);

                    setFocusChild(txtInfo, brdInfo, () =>
                    {
                        //Console.WriteLine("S");
                        Hook.I().RemoveKeyHook(onD, onU).ContinueWith((t) =>
                        {
                            if (proposedKey == Key.None)
                            {
                                return;
                            }
                            //Console.WriteLine("S");
                            Dispatcher.Invoke(() =>
                            {
                                kfK.SetKey(proposedKey);
                            });
                        });
                    });
                }

                base.txtInfo_MouseDown(sender, e);
            }
        private void selectDelegate(OnMouseLocationSelected callback, Action <int, int> update)
        {
            show(MyColors.BLUE);

            Action loop = null;

            object syncLock    = new object();
            bool   followMouse = true;

            Hook.OnMouseDelegate mouseDown = null;
            mouseDown = (ma, x, y) =>
            {
                if (ma != MouseAction.WM_LBUTTONDOWN)
                {
                    return;
                }

                lock (syncLock)
                {
                    followMouse = false;
                }

                hide();

                System.Drawing.Point p = CursorMonitor.Position();
                Hook.I().RemoveMouseHook(mouseDown).ContinueWith((t) =>
                {
                    loop = () => { };
                    callback(p.X, p.Y);
                });
            };
            Hook.I().AddMouseHook(mouseDown);

            Hook.OnKeyDelegate keyU = (k) => { };
            Hook.OnKeyDelegate keyD = null;
            keyD = (k) =>
            {
                if (k != Key.Escape)
                {
                    return;
                }

                lock (syncLock)
                {
                    followMouse = false;
                }

                Dispatcher.Invoke(() =>
                {
                    WindowState = WindowState.Minimized;
                    Visibility  = Visibility.Hidden;
                });

                Hook.I().RemoveKeyHook(keyD, keyU).ContinueWith((t) =>
                {
                    return(Hook.I().RemoveMouseHook(mouseDown));
                }).ContinueWith((t) =>
                {
                    callback(0, 0, true);
                });
            };
            Hook.I().AddKeyHook(keyD, keyU);

            TextBlock coords = new TextBlock();

            coords.Foreground = new SolidColorBrush(Colors.Black);
            coords.Background = new SolidColorBrush(Colors.White);
            coords.Padding    = new Thickness(4);

            loop = () =>
            {
                Topmost = true;

                canvas.Children.Clear();
                System.Drawing.Point p = CursorMonitor.Position();
                p.X = p.X == 0 ? 0 : p.X - 2;
                p.Y = p.Y == 0 ? 0 : p.Y - 2;
                update(p.X, p.Y);

                Line h = new Line();
                h.Stroke          = new SolidColorBrush(BLUE);
                h.StrokeThickness = 2;
                h.X1 = 0; h.X2 = W;
                h.Y1 = p.Y; h.Y2 = p.Y;

                Line v = new Line();
                v.Stroke          = new SolidColorBrush(BLUE);
                v.StrokeThickness = 2;
                v.X1 = p.X; v.X2 = p.X;
                v.Y1 = 0; v.Y2 = H;

                coords.Text = p.X + ", " + p.Y;
                double fac    = 15;
                double coordX = W - p.X < coords.ActualWidth + fac ? W - (coords.ActualWidth + fac) : p.X + 4;
                double coordY = p.Y < coords.ActualHeight + fac ? coords.ActualHeight + fac : p.Y;

                Canvas.SetLeft(coords, coordX);
                Canvas.SetBottom(coords, H - coordY);

                canvas.Children.Add(h);
                canvas.Children.Add(v);
                canvas.Children.Add(coords);

                //return;
                lock (syncLock)
                {
                    if (!followMouse)
                    {
                        return;
                    }
                }

                Task.Delay(16).ContinueWith((t) =>
                {
                    Dispatcher.Invoke(() =>
                    {
                        loop();
                    });
                });
            };
            Dispatcher.Invoke(loop);
        }
        private void btnRecord_Click(object sender, RoutedEventArgs e)
        {
            lock (this)
            {
                if (isRecording)
                {
                    stopRecord();
                }
                else
                {
                    //btnRecord.Visibility = Visibility.Hidden;
                    taskbarInfo.ProgressState = TaskbarItemProgressState.Indeterminate;
                    WindowState = WindowState.Minimized;
                    recManager.RecordBegin();

                    int                shiftDown = 0;
                    object             syncLock  = new object();
                    Hook.OnKeyDelegate onU       = (key) => {
                        if (key == Key.LeftShift || key == Key.RightShift)
                        {
                            lock (syncLock)
                            {
                                shiftDown--;
                            }
                        }
                    };
                    Hook.OnKeyDelegate onD = (key) =>
                    {
                        lock (syncLock)
                        {
                            if (key == Key.LeftShift || key == Key.RightShift)
                            {
                                shiftDown++;
                            }
                            else if (key == Key.Escape && shiftDown > 0)
                            {
                                Dispatcher.Invoke(() =>
                                {
                                    stopRecord();
                                });
                            }
                        }
                    };
                    Hook.I().AddKeyHook(onD, onU);

                    stopRecord = () =>
                    {
                        recManager.RecordEnd();
                        taskbarInfo.ProgressState = TaskbarItemProgressState.None;
                        btnRecord.Visibility      = Visibility.Visible;
                        isRecording = false;

                        WindowState = WindowState.Normal;
                        this.Activate();

                        this.Topmost = true;
                        this.Topmost = false;
                        Hook.I().RemoveKeyHook(onD, onU);
                        stopRecord = () => { };
                    };
                }

                isRecording = !isRecording;
            }
        }
Example #4
0
        private void waitForStopRec()
        {
            Hook hook = Hook.I();

            Hook.OnKeyDelegate tempOnU = (k) => { };
            Hook.OnKeyDelegate tempOnD = null;
            tempOnD = (k) =>
            {
                //Console.WriteLine(k);
                // one at a time
                if (k != Key.Escape)
                {
                    return;
                }
                //Console.WriteLine("es");
                hook.RemoveKeyHook(tempOnD, tempOnU);

                Task.Delay(0).ContinueWith((t) =>
                {
                    float lastT               = Time.Now(), startT, lastPol = lastT;
                    const float maxDelay      = 0.3f;
                    const float minRun        = 0.7f;
                    const float maxRun        = 1f;
                    const int minTravel       = 25;
                    Point lastP               = CursorMonitor.Position();
                    LinkedList <Point> points = new LinkedList <Point>();
                    points.AddLast(lastP);

                    while (lastP == CursorMonitor.Position())
                    {
                    }
                    startT = Time.Now();

                    while (true)
                    {
                        Point p = CursorMonitor.Position();
                        if (Math.Abs(p.X - lastP.X) > minTravel &&
                            Math.Abs(p.Y - lastP.Y) > minTravel)
                        {
                            //Console.WriteLine("pol");
                            points.AddLast(CursorMonitor.Position());
                            lastPol = Time.Now();
                            lastP   = CursorMonitor.Position();
                        }

                        float now = Time.Now();
                        if ((now - lastPol > maxDelay && now - startT > minRun) || now - startT > maxRun)
                        {
                            if (evalCirc(points))
                            {
                                foreach (Action c in callBacks)
                                {
                                    c();
                                }
                                callBacks.Clear();
                                //Console.WriteLine("det");
                            }
                            else
                            {
                                hook.AddKeyHook(tempOnD, tempOnU);
                                //Console.WriteLine("fail");
                            }
                            break;
                        }

                        lastT = Time.Now();
                    }
                });
            };
            hook.AddKeyHook(tempOnD, tempOnU);
        }