public static void AddAction(Action action, KeyTriggerState triggerOn, params Keys[] keyboardKeys) { Dictionary<Keys, KeyTriggerState> keyboardTriggers = null; // ha az action már benn van, akkor lekérjük az hozzátartozó billentyű + state dictionaryt if (keyboardActions.TryGetValue(action, out keyboardTriggers)) { // az összes beadott billentyűn végigmegyünk foreach (Keys keyboardKey in keyboardKeys) { if (keyboardTriggers.ContainsKey(keyboardKey)) { // ha eddig is bennvolt a key akkor a state-jéhez hozzá bitwise OR-ozzuk a 'triggerOn'-ban megadottat keyboardTriggers[keyboardKey] |= triggerOn; } else { // ha ez a billentyű még egyáltalán nem volt benn akkor a megadott 'triggerOn' paraméterrel // hozzáadjuk ennek az action-nek dictionaryjéhez keyboardTriggers.Add(keyboardKey, triggerOn); } } } else { keyboardTriggers = new Dictionary<Keys, KeyTriggerState>(); foreach (Keys keyboardKey in keyboardKeys) { keyboardTriggers.Add(keyboardKey, triggerOn); } keyboardActions.Add(action, keyboardTriggers); } }
public static void RemoveKeyTriggerState(Action action, Keys keyboardKey, KeyTriggerState dontTriggerOn) { Dictionary<Keys, KeyTriggerState> keyboardTriggers = null; if (keyboardActions.TryGetValue(action, out keyboardTriggers)) { if (keyboardTriggers.ContainsKey(keyboardKey)) { // bitwise & PLUS bitwise complement EQUALS remove flag keyboardTriggers[keyboardKey] &= ~dontTriggerOn; } } }