public static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { int vkCode = Marshal.ReadInt32(lParam); if (!_listenerEnabled && !changeBinding && vkCode != Config.CurrentConfig.ToggleSystemBinding) { return(CallNextHookEx(_hookID, nCode, wParam, lParam)); } if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN) { if (changeBinding) { if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleOverlay) { Config.CurrentConfig.ToggleOverlayBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleProfile) { Config.CurrentConfig.ToggleProfileBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleSystem) { Config.CurrentConfig.ToggleSystemBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.ToggleMode) { Config.CurrentConfig.ToggleModeBinding = vkCode; } else if (SetBindingForm._currentForm.BindingType == KeyBinding.Record) { Config.CurrentConfig.RecordBinding = vkCode; } else { for (int i = 0; i < SoundProfile.CurrentSoundProfile.Bindings.Length; i++) { int tempCode = SoundProfile.CurrentSoundProfile.Bindings[i]; if (tempCode == vkCode && SetBindingForm._currentForm.CurrentButton != i) { SoundProfile.CurrentSoundProfile.Bindings[i] = 0; SetBindingForm._currentForm.RemovedBinding = i; break; } SoundProfile.CurrentSoundProfile.Bindings[SetBindingForm._currentForm.CurrentButton] = vkCode; SoundProfile.CurrentSoundProfile.SaveSoundProfile(); } } //Set new binding SetBindingForm._currentForm.NewBindingSet = true; SetBindingForm._currentForm.Close(); return((System.IntPtr) 1); } else { if (vkCode == Config.CurrentConfig.ToggleOverlayBinding) { if (Overlay._currentOverlay.Visible) { Overlay._currentOverlay.Hide(); } else { Overlay._currentOverlay.Show(); } return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleProfileBinding) { SoundProfile.Next(); return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleSystemBinding) { MainForm._currentForm.ToggleSystemEnabled(null); Overlay._currentOverlay.UpdateStatusColor(); return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.ToggleModeBinding) { SoundSystem.KillAllSounds(); SoundSystem.SwitchSoundMode(); if (SettingsForm._currentForm != null) { SettingsForm._currentForm.SetKeyPressBoxSelectedIndex(); } return((System.IntPtr) 1); } else if (vkCode == Config.CurrentConfig.RecordBinding) //Control button on keyboard { isRecording = true; //Enables recording } else if (!isRecording) { if (SoundSystem.PlaySound(Utilities.ConvertKeyCodeToButtonId(vkCode))) { if (Config.CurrentConfig.InterruptKeys) { return((System.IntPtr) 1); } } } else { if (SoundSystem.RecordSound(Utilities.ConvertKeyCodeToButtonId(vkCode))) { if (Config.CurrentConfig.InterruptKeys) { return((System.IntPtr) 1); } } } } } else if (nCode >= 0 && wParam == (IntPtr)WM_KEYUP) { if (vkCode == Config.CurrentConfig.RecordBinding) //Control button on keyboard { isRecording = false; SoundSystem.StopRecording(); //if ctrl is released stop all recording } } return(CallNextHookEx(_hookID, nCode, wParam, lParam)); }
//eventhandler to play the sound private void ButtonClickPlay(object o, EventArgs e) { SoundSystem.PlaySound(Convert.ToInt16(((Button)o).Name.Substring(3))); }