public Main() { InitializeComponent(); // Initialize the config file config = new Config(this, overlay); // Overlay setup overlay.Show(); overlay.TopMost = true; overlay.Bounds = Screen.AllScreens[0].Bounds; button_colorDialog.BackColor = overlay.cursorColor; // Attempt to load the config file, if any config.LoadConfig(); // Low level mouse hook (MouseHook.cs) MouseHook.Start(); MouseHook.MouseDownHooked += new EventHandler(MouseDownHandler); MouseHook.MouseUpHooked += new EventHandler(MouseUpHandler); MouseHook.MouseMoveHooked += new EventHandler(MouseMoveHandler); // Mouse smoothing updater lineSmoothingTimer.Elapsed += new ElapsedEventHandler(LineSmoothingUpdate); lineSmoothingTimer.Interval = 5; // Line processing updater lineProcessingTimer.Elapsed += new ElapsedEventHandler(LineProcessingUpdate); lineProcessingTimer.Interval = config.smoothingStrength; // Register a raw input listener int size = Marshal.SizeOf(typeof(RawInputDevice)); RawInputDevice[] devices = new RawInputDevice[1]; devices[0].UsagePage = 1; devices[0].Usage = 2; devices[0].Flags = 0x00000100; devices[0].Target = Handle; RegisterRawInputDevices(devices, 1, size); }
// Overlay tab handling private void checkBox_disableOverlay_CheckedChanged(object sender, EventArgs e) { if (checkBox_disableOverlay.Checked) { overlayForm.Hide(); config.disableOverlay = true; } else { overlayForm.Show(); config.disableOverlay = false; } }
public void LoadConfig(bool def = false) { if (def) { tabletOffset = new Point(0, 0); overrideBounds = new Rectangle(0, 0, 0, 0); smoothingStrength = 30; smoothingInterpolation = 4; overlayScreen = 0; tolerance = 300; manualInterpolation = false; stayOnTop = false; disableOverlay = false; allScreens = false; manualOverlayOverride = false; disableCatchUp = false; snapToCursor = false; smoothOnDraw = false; tabletOffsetOverride = false; disableAutoDetection = false; hotkeys[0] = "None"; hotkeys[1] = "None"; hotkeys[2] = "None"; hotkeys[3] = "None"; hotkeys[4] = "None"; hotkeys[5] = "None"; // Main window resetting mainForm.checkBox_smoothOnDraw.Checked = false; mainForm.checkBox_stayOnTop.Checked = false; mainForm.checkBox_tabletMode.Checked = false; mainForm.checkBox_tabletMode.Enabled = false; mainForm.checkBox_manualInterpolation.Checked = false; mainForm.trackBar_smoothingInterpolation.Enabled = false; mainForm.textBox_smoothingInterpolation.Enabled = false; mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString(); mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString(); mainForm.checkBox_smoothOnDraw.Checked = false; mainForm.TopMost = false; // Cursor and overlay resetting overlayForm.cursorColor = Color.FromArgb(128, 128, 128); overlayForm.cursorFillColor = Color.FromArgb(255, 255, 254); overlayForm.cursorType = Overlay.CursorType.Bullseye; overlayForm.Show(); overlayForm.Bounds = Screen.PrimaryScreen.Bounds; mainForm.button_colorDialog.BackColor = overlayForm.cursorColor; // Hotkey resetting for (int i = 0; i < mainForm.hotKeyHandling.Count(); i++) { try { mainForm.hotKeyHandling[i].Dispose(); } catch { // Nothing to dispose! } } } else { try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Main window loading smoothingStrength = int.Parse(config.AppSettings.Settings["Strength"].Value); smoothingInterpolation = int.Parse(config.AppSettings.Settings["Interpolation"].Value); manualInterpolation = bool.Parse(config.AppSettings.Settings["Manual Interpolation"].Value); smoothOnDraw = bool.Parse(config.AppSettings.Settings["Smooth On Draw"].Value); stayOnTop = bool.Parse(config.AppSettings.Settings["Stay On Top"].Value); disableAutoDetection = bool.Parse(config.AppSettings.Settings["Disable Auto Detection"].Value); mainForm.tabletMode = bool.Parse(config.AppSettings.Settings["Tablet Mode"].Value); mainForm.checkBox_tabletMode.Enabled = disableAutoDetection; mainForm.checkBox_tabletMode.Checked = mainForm.tabletMode; mainForm.checkBox_smoothOnDraw.Checked = smoothOnDraw; if (manualInterpolation) { mainForm.checkBox_manualInterpolation.Checked = true; mainForm.trackBar_smoothingInterpolation.Enabled = true; mainForm.textBox_smoothingInterpolation.Enabled = true; } mainForm.textBox_smoothingInterpolation.Text = smoothingInterpolation.ToString(); mainForm.textBox_smoothingStrength.Text = smoothingStrength.ToString(); if (stayOnTop) { mainForm.checkBox_stayOnTop.Checked = true; mainForm.TopMost = true; overlayForm.TopMost = true; } // Cursor and overlay loading overlayForm.cursorType = (Overlay.CursorType)Enum.Parse(typeof(Overlay.CursorType), config.AppSettings.Settings["Cursor Graphic"].Value); overlayForm.cursorColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Main Color"].Value); overlayForm.cursorFillColor = ColorTranslator.FromHtml(config.AppSettings.Settings["Fill Color"].Value); overlayScreen = int.Parse(config.AppSettings.Settings["Overlay Screen"].Value); disableOverlay = bool.Parse(config.AppSettings.Settings["Disable Overlay"].Value); allScreens = bool.Parse(config.AppSettings.Settings["All Screens"].Value); manualOverlayOverride = bool.Parse(config.AppSettings.Settings["Manual Overlay Override"].Value); RectangleConverter r = new RectangleConverter(); overrideBounds = (Rectangle)r.ConvertFromString(config.AppSettings.Settings["Override Bounds"].Value); if (disableOverlay) { overlayForm.Hide(); } overlayForm.Bounds = Screen.AllScreens[overlayScreen].Bounds; if (allScreens) { overlayForm.Bounds = new Rectangle(0, 0, SystemInformation.VirtualScreen.Width, SystemInformation.VirtualScreen.Height); } if (manualOverlayOverride) { overlayForm.Bounds = overrideBounds; } mainForm.button_colorDialog.BackColor = overlayForm.cursorColor; // ...and everything else disableCatchUp = bool.Parse(config.AppSettings.Settings["Disable Catch Up"].Value); snapToCursor = bool.Parse(config.AppSettings.Settings["Snap To Cursor"].Value); tolerance = int.Parse(config.AppSettings.Settings["Tolerance"].Value); tabletOffsetOverride = bool.Parse(config.AppSettings.Settings["Tablet Offset Override"].Value); PointConverter p = new PointConverter(); tabletOffset = (Point)p.ConvertFromString(config.AppSettings.Settings["Tablet Offset"].Value); KeysConverter c = new KeysConverter(); Keys k; Hotkey.KeyModifiers m; hotkeys[0] = config.AppSettings.Settings["Hotkey 1"].Value; if (hotkeys[0] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 1"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 0, m, k); } } hotkeys[1] = config.AppSettings.Settings["Hotkey 2"].Value; if (hotkeys[1] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 2"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 1, m, k); } } hotkeys[2] = config.AppSettings.Settings["Hotkey 3"].Value; if (hotkeys[2] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 3"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 2, m, k); } } hotkeys[3] = config.AppSettings.Settings["Hotkey 4"].Value; if (hotkeys[3] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 4"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 3, m, k); } } hotkeys[4] = config.AppSettings.Settings["Hotkey 5"].Value; if (hotkeys[4] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 5"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 4, m, k); } } hotkeys[5] = config.AppSettings.Settings["Hotkey 6"].Value; if (hotkeys[5] != "None") { k = (Keys)c.ConvertFromString(config.AppSettings.Settings["Hotkey 6"].Value); m = Hotkey.GetModifiers(k, out k); if (k != Keys.None) { mainForm.RegisterHotkey(mainForm.Handle, 5, m, k); } } } catch { // Quietly fail loading bad configs or no configs } } }