Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var globalHooker = new MKB.WinApi.GlobalHooker();

            using (var mouseOverlay = new MouseOverlay())
                using (var kbOverlay = new KeyboardOverlay())
                    using (var msListener = new MKB.MouseHookListener(globalHooker))
                        using (var kbListener = new MKB.KeyboardHookListener(globalHooker))
                        {
                            msListener.MouseDown  += (sender, eventArgs) => mouseOverlay.MouseDown(eventArgs);
                            msListener.MouseMove  += (sender, eventArgs) => mouseOverlay.MouseMove(eventArgs);
                            msListener.MouseUp    += (sender, eventArgs) => mouseOverlay.MouseUp(eventArgs);
                            msListener.MouseWheel += (sender, eventArgs) => mouseOverlay.MouseWheel(eventArgs);

                            kbListener.KeyDown += (sender, eventArgs) => kbOverlay.KeyDown(eventArgs);

                            msListener.Start();
                            kbListener.Start();

                            Application.Run();

                            msListener.Stop();
                            kbListener.Stop();
                        }
        }
Ejemplo n.º 2
0
        public MainWindow()
        {
            InitializeComponent();

            MouseActions = new MouseActionViewModel();
            Settings     = new Settings();

            if (File.Exists(Settings.SettingsFilename))
            {
                Settings = JsonConvert.DeserializeObject <Settings>(File.ReadAllText(Settings.SettingsFilename));
                AutorunCheckbox.IsChecked = Settings.Autorun;
            }

            if (File.Exists(Settings.AutosaveFilename))
            {
                var autoload = File.ReadAllText(Settings.AutosaveFilename);
                var actions  = JsonConvert.DeserializeObject <JArray>(autoload);
                foreach (var action in actions)
                {
                    var xPosition = (int)action["XPosition"];
                    var yPosition = (int)action["YPosition"];
                    var cooldown  = (TimeSpan)action["Cooldown"];
                    var type      = (ActionType)(int)action["Type"];
                    var clickType = (ClickType)(int)action["Button"];
                    var text      = (string)action["Text"];
                    MouseActions.Actions.Add(new Action(xPosition, yPosition, cooldown, clickType, type, text));
                }

                if (Settings.Autorun)
                {
                    MouseActions.RunActions();
                }
            }

            MouseKeyboardActivityMonitor.WinApi.GlobalHooker h = new MouseKeyboardActivityMonitor.WinApi.GlobalHooker();

            M = new MouseHookListener(h);

            M.MouseClick += (object s, System.Windows.Forms.MouseEventArgs e) =>
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Middle && MouseActions.IsRunning == false)
                {
                    MouseActions.Actions.Add(new Action(
                                                 e.X,
                                                 e.Y,
                                                 Settings.DefaultCooldown
                                                 ));
                }
            };

            App.Current.Exit += (object sender, ExitEventArgs e) =>
            {
                MouseActions.IsStopRequested = true;
                M?.Stop();

                WriteToJsonFile <Collection <Action> >(Settings.AutosaveFilename, MouseActions.Actions);
                WriteToJsonFile <Settings>(Settings.SettingsFilename, Settings);
            };

            M.Start();
        }