Exemple #1
0
 private void Event_DisplaySettingsChanged(object sender, EventArgs e)
 {
     UpdatingDisplaySettings = true;
     Debug.WriteLine("\nDisplay Settings Changed...");
     SnagScreen.Init(Screen.AllScreens);
     Debug.WriteLine(SnagScreen.GetScreenInformation());
     UpdatingDisplaySettings = false;
 }
Exemple #2
0
        private void Run(string[] args)
        {
            // DPI Awareness API is not available on older OS's, but they work in
            // physical pixels anyway, so we just ignore if the call fails.
            try
            {
                NativeMethods.SetProcessDpiAwareness(NativeMethods.PROCESS_DPI_AWARENESS.Process_Per_Monitor_DPI_Aware);
            }
            catch (DllNotFoundException)
            {
                Debug.WriteLine("No SHCore.DLL. No problem.");
            }

            // Parse command line arguments
            foreach (string arg in args)
            {
                switch (arg)
                {
                case "-s":
                    IsUnstickEnabled = false;
                    break;

                case "+s":
                    IsUnstickEnabled = true;
                    break;

                case "-j":
                    IsJumpEnabled = false;
                    break;

                case "+j":
                    IsJumpEnabled = true;
                    break;

                case "-w":
                    IsScreenWrapEnabled = false;
                    break;

                case "+w":
                    IsScreenWrapEnabled = true;
                    break;

                default:
                    string exeName = Environment.GetCommandLineArgs()[0];
                    Console.WriteLine($"Usage: {exeName} [options ...]");
                    Console.WriteLine("\t-s    Disables mouse un-sticking.");
                    Console.WriteLine("\t+s    Enables mouse un-sticking. Default.");
                    Console.WriteLine("\t-j    Disables mouse jumping.");
                    Console.WriteLine("\t+j    Enables mouse jumping. Default.");
                    Console.WriteLine("\t-w    Disables mouse wrapping.");
                    Console.WriteLine("\t+w    Enables mouse wrapping. Default.");
                    Environment.Exit(1);
                    break;
                }
            }

            SnagScreen.Init(Screen.AllScreens);

            Debug.WriteLine(SnagScreen.GetScreenInformation());

            // Get notified of any screen configuration changes.
            SystemEvents.DisplaySettingsChanged += Event_DisplaySettingsChanged;

            // Keep a reference to the delegate, so it does not get garbage collected.
            MouseHookDelegate = LLMouseHookCallback;
            LLMouse_hookhand  = SetHook(NativeMethods.WH_MOUSE_LL, MouseHookDelegate);

            // This is the one that runs "forever" while the application is alive, and handles
            // events, etc. This application is ABSOLUTELY ENTIRELY driven by the LLMouseHook
            // and DisplaySettingsChanged events.
            Application.Run(new MyCustomApplicationContext(this));

            Debug.WriteLine("Exiting!!!");
            UnsetHook(ref LLMouse_hookhand);
            SystemEvents.DisplaySettingsChanged -= Event_DisplaySettingsChanged;
        }