public BindControl(Sound sound) { InitializeComponent(); this.sound = sound; textBoxBind.Text = sound.BindToString(); Hook.GetForm().InitKeyboard(); timer = new Timer(); timer.Interval = 16; timer.Tick += new EventHandler(timer_Tick); timer.Start(); toolTip1.SetToolTip(textBoxBind, "Bind already exists"); }
public SoundItem(Sound sound) { InitializeComponent(); this.sound = sound; SetFields(); if (!Hook.GetForm().CheckWave(sound.Filename)) { // Show warning toolTip1.SetToolTip(pictureBoxWarning, "Invalid Wav format"); pictureBoxWarning.Visible = true; } else { toolTip1.RemoveAll(); pictureBoxWarning.Visible = false; } }
// Check binds void timer_Tick(object sender, EventArgs e) { if (lastBind != 0) { float time = (float)(HighResolutionTimer.Ticks-lastBind) / (float)HighResolutionTimer.Frequency * 1000f; if (time < 500f) // wait 500ms between accepting binds return; } List<Key> keys = PollKeyboard(); // Compare all binds against held keys bool ExclusiveKeys = Properties.Settings.Default.ExclusiveKeys; foreach (Sound sound in sounds.SoundList) { bool allDown = false; if (!ExclusiveKeys) { foreach (Key bindKey in sound.Bind) { bool thisDown = false; foreach (Key downKey in keys) { if (downKey == bindKey) { thisDown = true; break; } } if (!thisDown) break; else allDown = true; } } else { int numFound = 0; foreach (Key downKey in keys) { bool thisDown = false; foreach (Key bindKey in sound.Bind) { if (downKey == bindKey) { thisDown = true; numFound++; break; } } if (!thisDown) break; else if(numFound == sound.Bind.Count) allDown = true; } } // This bind has been activated... if (allDown && ActiveSound != sound && File.Exists(sound.Filename)) { ActiveSound = sound; File.Copy(sound.Filename, Properties.Settings.Default.HLPath + "/" + Properties.Settings.Default.SoundDestName, true); System.Console.WriteLine("Copying " + sound.Filename); lastBind = HighResolutionTimer.Ticks; break; } } }
// stop listening, moving files, etc. public void Disable() { // Enable UI LockChanged(true); sounds = null; ActiveSound = null; if (timer != null) timer.Stop(); CloseKeyboard(); }