/// <param name="kb">check if this key bind is being triggered</param> /// <param name="list">where to mark if this is indeed triggered</param> /// <param name="additionalFilter">an additional gate that might prevent this particluar keybind from triggering. possibly heavy method, so only checked if the key is triggered</param> bool KeyCheck(KBind kb, List <KeyTrigger> list, Func <KBind, bool> additionalFilter = null) { KCombination kp = trigger(kb); if (kp != null && (additionalFilter == null || !additionalFilter.Invoke(kb))) { list.Add(new KeyTrigger { kb = kb, kp = kp }); return(true); } return(false); }
public bool IsValueChanged() { bool isAllowed = modifiers == null || modifiers.Length == 0 || KCombination.IsSatisfiedHeld(modifiers); if (!isAllowed) { if (!stickyInput) { cachedValue = 0; } } else { cachedValue = filteredValue ? GetValue() : GetValueRaw(); } return(cachedValue != knownValue); }
public override string ToString() { return(KCombination.ToString(modifiers) + name); }
/// <summary> /// describes functions to execute when a specific key-combination is pressed/held/released /// </summary> public KBind(KCombination kCombo, string name = null, Func <bool> onPressEvent = null, Func <bool> onHoldEvent = null, Func <bool> onReleaseEvent = null, Func <bool> additionalRequirement = null, bool eventAlwaysTriggerable = false, InvokeSet pressFunc = null, InvokeSet holdFunc = null, InvokeSet releaseFunc = null) : this(new[] { kCombo }, name, onPressEvent, onHoldEvent, onReleaseEvent, additionalRequirement, eventAlwaysTriggerable, pressFunc, holdFunc, releaseFunc) { }
public void UpdateCurrentKeyBindText() { EnsureInitializedKeyBindGroups(); StringBuilder sb = new StringBuilder(); for (int s = 0; s < keyBindGroups.Length; ++s) { KBindGroup ks = keyBindGroups[s]; if (ks.keyBindList.Count == 0) { continue; } sb.Append("[" + ks.name + "]\n"); for (int i = 0; i < ks.keyBindList.Count; ++i) { KBind kb = ks.keyBindList[i]; bool needsPriority = true; bool hasKeys = true; if (kb.keyCombinations.Length != 0 && (kb.keyCombinations.Length != 1 || kb.keyCombinations[0].key != KCode.None)) { KCombination theseKeys = kb.keyCombinations[0]; bool hasPrev = i > 0; bool hasNext = i < ks.keyBindList.Count - 1; KBind prev = (hasPrev) ? ks.keyBindList[i - 1] : null; KBind next = (hasNext) ? ks.keyBindList[i + 1] : null; KCombination prevKeys = hasPrev && prev.keyCombinations.Length > 0 ? prev.keyCombinations[0] : null; KCombination nextKeys = hasNext && next.keyCombinations.Length > 0 ? next.keyCombinations[0] : null; needsPriority = (prevKeys != null && prevKeys.CompareTo(theseKeys) == 0 || nextKeys != null && nextKeys.CompareTo(theseKeys) == 0); } else { hasKeys = false; } if (hasKeys) { sb.Append(kb.ShortDescribe(" | ")); } else { sb.Append("(no keys)"); } sb.Append(" :"); if (needsPriority) { sb.Append(kb.priority.ToString()); } sb.Append(": "); sb.Append(kb.name); sb.Append("\n"); } } if (axisBinds.Count > 0) { sb.Append("[Axis]\n"); for (int i = 0; i < axisBinds.Count; ++i) { AxBind ab = axisBinds[i]; sb.Append(ab.ShortDescribe(" | ")); sb.Append(" :: "); sb.Append(ab.name); sb.Append("\n"); } } CurrentKeyBindings = sb.ToString(); }