public int AddNewAudioHotkey(string key, string files, float volume, Guid audioDevice, int startingTime = 0, string name = "") { KeyAndModifiers fullKey = CreateAndValidateFullKey(key); AudioHotkey hk = new AudioHotkey(fullKey, audioDevice, files, volume, startingTime, name); CheckHotkeyResult(hk.Register(mainFrm), key); hotkeysList.Add(hk); return(hk.Id); }
public int AddNewControlHotkey(string key, ControlRoles role, out string displayedVal, string holdDownKey = "", float flowChangeValue = 0) { ControlHotkey ctrlHk = null; KeyAndModifiers fullKey = CreateAndValidateFullKey(key); displayedVal = ""; ctrlHk = new ControlHotkey(fullKey, role); switch (role) { case ControlRoles.Forward: case ControlRoles.Backward: ctrlHk.FlowChangeValue = flowChangeValue; displayedVal = flowChangeValue + " sec"; break; case ControlRoles.IncreaseVolume: case ControlRoles.DecreaseVolume: ctrlHk.FlowChangeValue = flowChangeValue; displayedVal = flowChangeValue + "%"; break; case ControlRoles.HoldDownKey: ctrlHk.HoldDownKey = keysTranslater.StringToKeyCode(holdDownKey); displayedVal = holdDownKey; break; case ControlRoles.IncreaseTempo: case ControlRoles.DecreaseTempo: case ControlRoles.IncreaseSpeed: case ControlRoles.DecreaseSpeed: ctrlHk.FlowChangeValue = flowChangeValue; displayedVal = flowChangeValue + "%"; break; case ControlRoles.IncreasePitch: case ControlRoles.DecreasePitch: ctrlHk.FlowChangeValue = flowChangeValue; displayedVal = "+" + (flowChangeValue / 10) + ((flowChangeValue / 10) >= 2 ? " semitones" : " semitone"); break; case ControlRoles.MasterHotkey: ctrlHk = null; if (MasterHotkey.Registered) { throw new MasterHotkeyUsedException(MasterHotkey.Key.FullKeyString); } MasterHotkey.Key = fullKey; CheckHotkeyResult(MasterHotkey.Register(mainFrm), key); return(MasterHotkey.Id); } CheckHotkeyResult(ctrlHk.Register(mainFrm), key); hotkeysList.Add(ctrlHk); return(ctrlHk.Id); }
public string RemapKey(string fullkey, short originalLayoutIdentifier) { KeyAndModifiers key = new KeyAndModifiers(fullkey); string remappedKey = key.ModifiersString + keysTranslater.KeyCodeToString(keysTranslater.ReMapKey(originalLayoutIdentifier, key.KeyString)); if (remappedKey == "Keys.None" || remappedKey == "None") { throw new KeyRemappingFailedException(fullkey, originalLayoutIdentifier); } return(remappedKey); }
public bool IsKeyAlreadyUsed(KeyAndModifiers fullKey) { bool result; IHotkey hk; hk = hotkeysList.Find(hkey => hkey.Key.ToString() == fullKey.FullKeyString); result = hk != null; result |= MasterHotkey.Registered && (fullKey.FullKeyString == MasterHotkey.Key.FullKeyString); return(result); }
public void ModifyHotkey(int hotkeyId, string newKey) { IHotkey hk = FindHotkeyById(hotkeyId); KeyAndModifiers newFullKey = CreateAndValidateFullKey(newKey); KeyAndModifiers oldFullKey = hk.Key; hk.Key = newFullKey; int result = hk.Reregister(); if (result != 1 && result != -3) { hk.Key = oldFullKey; hk.Register(mainFrm); CheckHotkeyResult(result, newKey); } }
public KeyAndModifiers CreateAndValidateFullKey(string key) { if (key == "") { throw new KeyMissingException(); } KeyAndModifiers fullKey = new KeyAndModifiers(key); if (!fullKey.IsActualKey()) { throw new KeyInvalidException(key); } if (IsKeyAlreadyUsed(fullKey)) { throw new KeyAlreadyUsedException(key); } return(fullKey); }