private void RegisterScrolling(CompositeHook hook) { var mouse = hook.GetMouse(); var name = mouse.Information.InstanceName + " " + mouse.Information.InstanceGuid; ScrollUp = new KeyOrButton(new GamepadButton(name, "Scroll_Up")); ScrollDown = new KeyOrButton(new GamepadButton(name, "Scroll_Down")); hook.RegisterHotKey(ScrollUp); hook.RegisterHotKey(ScrollDown); }
public CounterComponentSettings() { InitializeComponent(); Hook = new CompositeHook(); // Set default values. GlobalHotkeysEnabled = false; CounterFont = new Font("Segoe UI", 13, FontStyle.Regular, GraphicsUnit.Pixel); OverrideCounterFont = false; CounterTextColor = Color.FromArgb(255, 255, 255, 255); CounterValueColor = Color.FromArgb(255, 255, 255, 255); OverrideTextColor = false; BackgroundColor = Color.Transparent; BackgroundColor2 = Color.Transparent; BackgroundGradient = GradientType.Plain; CounterText = "Counter:"; InitialValue = 0; Increment = 1; // Hotkeys IncrementKey = new KeyOrButton(Keys.Add); DecrementKey = new KeyOrButton(Keys.Subtract); ResetKey = new KeyOrButton(Keys.NumPad0); // Set bindings. txtIncrement.Text = FormatKey(IncrementKey); txtDecrement.Text = FormatKey(DecrementKey); txtReset.Text = FormatKey(ResetKey); txtCounterText.DataBindings.Add("Text", this, "CounterText"); numInitialValue.DataBindings.Add("Value", this, "InitialValue"); numIncrement.DataBindings.Add("Value", this, "Increment"); chkGlobalHotKeys.DataBindings.Add("Checked", this, "GlobalHotkeysEnabled", false, DataSourceUpdateMode.OnPropertyChanged); chkFont.DataBindings.Add("Checked", this, "OverrideCounterFont", false, DataSourceUpdateMode.OnPropertyChanged); lblFont.DataBindings.Add("Text", this, "CounterFontString", false, DataSourceUpdateMode.OnPropertyChanged); chkColor.DataBindings.Add("Checked", this, "OverrideTextColor", false, DataSourceUpdateMode.OnPropertyChanged); btnColor.DataBindings.Add("BackColor", this, "CounterTextColor", false, DataSourceUpdateMode.OnPropertyChanged); btnColor3.DataBindings.Add("BackColor", this, "CounterValueColor", false, DataSourceUpdateMode.OnPropertyChanged); btnColor1.DataBindings.Add("BackColor", this, "BackgroundColor", false, DataSourceUpdateMode.OnPropertyChanged); btnColor2.DataBindings.Add("BackColor", this, "BackgroundColor2", false, DataSourceUpdateMode.OnPropertyChanged); cmbGradientType.DataBindings.Add("SelectedItem", this, "GradientString", false, DataSourceUpdateMode.OnPropertyChanged); // Assign event handlers. cmbGradientType.SelectedIndexChanged += cmbGradientType_SelectedIndexChanged; chkFont.CheckedChanged += chkFont_CheckedChanged; chkColor.CheckedChanged += chkColor_CheckedChanged; chkGlobalHotKeys.CheckedChanged += chkGlobalHotKeys_CheckedChanged; Load += CounterSettings_Load; RegisterHotKeys(); }
public SettingsDialog(CompositeHook hook, ISettings settings) { InitializeComponent(); Settings = settings; Hook = hook; txtStartSplit.DataBindings.Add("Text", this, "SplitKey"); txtReset.DataBindings.Add("Text", this, "ResetKey"); txtSkip.DataBindings.Add("Text", this, "SkipKey"); txtUndo.DataBindings.Add("Text", this, "UndoKey"); txtPause.DataBindings.Add("Text", this, "PauseKey"); txtToggle.DataBindings.Add("Text", this, "ToggleGlobalHotkeys"); txtSwitchPrevious.DataBindings.Add("Text", this, "SwitchComparisonPrevious"); txtSwitchNext.DataBindings.Add("Text", this, "SwitchComparisonNext"); chkGlobalHotkeys.DataBindings.Add("Checked", Settings, "GlobalHotkeysEnabled"); chkWarnOnReset.DataBindings.Add("Checked", Settings, "WarnOnReset"); chkDoubleTap.DataBindings.Add("Checked", Settings, "DoubleTapPrevention"); txtDelay.DataBindings.Add("Text", this, "HotkeyDelay"); cbxRaceViewer.DataBindings.Add("SelectedItem", this, "RaceViewer"); SetClickEvents(); }
public void RegisterHotkeys(CompositeHook hook) { try { UnregisterAllHotkeys(hook); } catch (Exception ex) { Log.Error(ex); } try { RegisterScrolling(hook); } catch (Exception ex) { Log.Error(ex); } if (SplitKey != null) { try { RegisterHotkey(hook, SplitKey); } catch (Exception e) { Log.Error(e); } } if (ResetKey != null) { try { RegisterHotkey(hook, ResetKey); } catch (Exception e) { Log.Error(e); } } if (SkipKey != null) { try { RegisterHotkey(hook, SkipKey); } catch (Exception e) { Log.Error(e); } } if (UndoKey != null) { try { RegisterHotkey(hook, UndoKey); } catch (Exception e) { Log.Error(e); } } if (PauseKey != null) { try { RegisterHotkey(hook, PauseKey); } catch (Exception e) { Log.Error(e); } } if (ToggleGlobalHotkeys != null) { try { RegisterHotkey(hook, ToggleGlobalHotkeys); } catch (Exception e) { Log.Error(e); } } if (SwitchComparisonPrevious != null) { try { RegisterHotkey(hook, SwitchComparisonPrevious); } catch (Exception e) { Log.Error(e); } } if (SwitchComparisonNext != null) { try { RegisterHotkey(hook, SwitchComparisonNext); } catch (Exception e) { Log.Error(e); } } }
public void UnregisterAllHotkeys(CompositeHook hook) { hook.UnregisterAllHotkeys(); HotkeyHook.Instance.UnregisterAllHotkeys(); }
private void RegisterHotkey(CompositeHook hook, KeyOrButton key) { hook.RegisterHotKey(key); if (DeactivateHotkeysForOtherPrograms && key.IsKey && GlobalHotkeysEnabled) { var args = new System.Windows.Forms.KeyEventArgs(key.Key); var modifiers = (args.Alt ? ModifierKeys.Alt : ModifierKeys.None) | (args.Shift ? ModifierKeys.Shift : ModifierKeys.None) | (args.Control ? ModifierKeys.Control : ModifierKeys.None); HotkeyHook.Instance.RegisterHotKey(modifiers, args.KeyCode); } }
private void Init(string splitsPath = null, string layoutPath = null) { SetWindowTitle(); SpeedrunCom.Authenticator = new SpeedrunComOAuthForm(); GlobalCache = new GraphicsCache(); Invalidator = new Invalidator(this); SetStyle(ControlStyles.SupportsTransparentBackColor, true); ComponentManager.BasePath = BasePath; SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed; SpeedRunsLiveAPI.Instance.RefreshRacesListAsync(); CurrentState = new LiveSplitState(null, this, null, null, null); ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); Model = new DoubleTapPrevention(new TimerModel()); RunFactory = new StandardFormatsRunFactory(); RunSaver = new XMLRunSaver(); LayoutSaver = new XMLLayoutSaver(); SettingsSaver = new XMLSettingsSaver(); LoadSettings(); UpdateRecentSplits(); UpdateRecentLayouts(); InTimerOnlyMode = false; var timerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory); IRun run = timerOnlyRun; try { if (!string.IsNullOrEmpty(splitsPath)) { run = LoadRunFromFile(splitsPath, TimingMethod.RealTime); } else if (Settings.RecentSplits.Count > 0) { var lastSplitFile = Settings.RecentSplits.Last(); if (!string.IsNullOrEmpty(lastSplitFile.Path)) { run = LoadRunFromFile(lastSplitFile.Path, lastSplitFile.LastTimingMethod); CurrentState.CurrentTimingMethod = lastSplitFile.LastTimingMethod; } } } catch (Exception e) { Log.Error(e); } run.FixSplits(); CurrentState.Run = run; CurrentState.Settings = Settings; try { if (!string.IsNullOrEmpty(layoutPath)) { Layout = LoadLayoutFromFile(layoutPath); } else { if (Settings.RecentLayouts.Count > 0 && !string.IsNullOrEmpty(Settings.RecentLayouts.Last())) { Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last()); } else if (run == timerOnlyRun) { Layout = new TimerOnlyLayoutFactory().Create(CurrentState); InTimerOnlyMode = true; } else { Layout = new StandardLayoutFactory().Create(CurrentState); } } } catch (Exception e) { Log.Error(e); Layout = new StandardLayoutFactory().Create(CurrentState); } CurrentState.LayoutSettings = Layout.Settings; CreateAutoSplitter(); CurrentState.FixTimingMethodFromRuleset(); SwitchComparisonGenerators(); SwitchComparison(Settings.LastComparison); Model.CurrentState = CurrentState; CurrentState.OnReset += CurrentState_OnReset; CurrentState.OnStart += CurrentState_OnStart; CurrentState.OnSplit += CurrentState_OnSplit; CurrentState.OnSkipSplit += CurrentState_OnSkipSplit; CurrentState.OnUndoSplit += CurrentState_OnUndoSplit; CurrentState.OnPause += CurrentState_OnPause; CurrentState.OnResume += CurrentState_OnResume; CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious; CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext; ComponentRenderer = new ComponentRenderer(); StartPosition = FormStartPosition.Manual; SetLayout(Layout); RefreshTask = Task.Factory.StartNew(RefreshTimerWorker); InvalidationRequired = false; Hook = new CompositeHook(); Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed; Settings.RegisterHotkeys(Hook); SizeChanged += TimerForm_SizeChanged; lock (BackBufferLock) { BackBuffer = new Bitmap(Width, Height); #if WITH_XSPLIT /*try { // Outputs a CosmoWright image every 50ms (20 FPS) XSplit = TimedBroadcasterPlugin.CreateInstance( "livesplit", BackBuffer, 50); if (this.XSplit != null) { // The correct version of XSplit was installed (unless they use OBS), so we can start our output. this.XSplit.StartTimer(); } } catch { }*/ #endif } TopMost = Layout.Settings.AlwaysOnTop; }
private void Init(String splitsPath = null, String layoutPath = null) { GlobalCache = new GraphicsCache(); Invalidator = new Invalidator(this); SetStyle(ControlStyles.SupportsTransparentBackColor, true); ComponentManager.BasePath = BasePath; SpeedRunsLiveAPI.Instance.RacesRefreshed += SRL_RacesRefreshed; SpeedRunsLiveAPI.Instance.RefreshRacesListAsync(); CurrentState = new LiveSplitState(null, null, null); ComparisonGeneratorsFactory = new StandardComparisonGeneratorsFactory(); TimerOnlyLayout = new TimerOnlyLayoutFactory().Create(CurrentState); TimerOnlyRun = new StandardRunFactory().Create(ComparisonGeneratorsFactory); InTimerOnlyMode = false; Model = new TimerModel(); //LiveSplit.Web.Share.Twitch.Instance.AutoUpdateModel = Model; RunFactory = new StandardFormatsRunFactory(); RunSaver = new XMLRunSaver(); LayoutSaver = new XMLLayoutSaver(); SettingsSaver = new XMLSettingsSaver(); LoadSettings(); UpdateRecentSplits(); UpdateRecentLayouts(); IRun run = null; if (!String.IsNullOrEmpty(splitsPath)) { run = LoadRunFromFile(splitsPath, true); } else { try { run = LoadRunFromFile(Settings.RecentSplits.Last(), true); } catch (Exception e) { Log.Error(e); run = TimerOnlyRun; } } if (!String.IsNullOrEmpty(layoutPath)) { Layout = LoadLayoutFromFile(layoutPath); } else { try { Layout = LoadLayoutFromFile(Settings.RecentLayouts.Last()); } catch (Exception e) { Log.Error(e); if (run == TimerOnlyRun) { Layout = TimerOnlyLayout; InTimerOnlyMode = true; } else Layout = new StandardLayoutFactory().Create(CurrentState); } } CurrentState.Run = run; CurrentState.LayoutSettings = Layout.Settings; CurrentState.Settings = Settings; RegenerateComparisons(); SwitchComparison(Settings.LastComparison); Model.CurrentState = CurrentState; CurrentState.OnReset += CurrentState_OnReset; CurrentState.OnStart += CurrentState_OnStart; CurrentState.OnSplit += CurrentState_OnSplit; CurrentState.OnSkipSplit += CurrentState_OnSkipSplit; CurrentState.OnUndoSplit += CurrentState_OnUndoSplit; CurrentState.OnPause += CurrentState_OnPause; CurrentState.OnResume += CurrentState_OnResume; CurrentState.OnSwitchComparisonPrevious += CurrentState_OnSwitchComparisonPrevious; CurrentState.OnSwitchComparisonNext += CurrentState_OnSwitchComparisonNext; ComponentRenderer = new ComponentRenderer(); this.StartPosition = FormStartPosition.Manual; SetLayout(Layout); OldSize = -20; RefreshTimer = new System.Timers.Timer(25f); RefreshTimer.Elapsed += timer_Elapsed; RefreshTimer.Enabled = true; RefreshCounter = 0; RefreshesRemaining = 0; Hook = new CompositeHook(); Hook.KeyOrButtonPressed += hook_KeyOrButtonPressed; Settings.RegisterHotkeys(Hook); RegisterTaskbarButtons(); this.SizeChanged += TimerForm_SizeChanged; lock (BackBufferLock) { BackBuffer = new Bitmap(this.Width, this.Height); } this.TopMost = Layout.Settings.AlwaysOnTop; }