public static IKeyAction GetKeyActionFromActionType(ActionTypes type, IAddOptions options, string GUID = "") { IKeyAction res = null; switch (type) { case ActionTypes.OpenProcess: res = new OpenProcessAction(options as OpenProcessOptions, GUID); break; case ActionTypes.ScreenCapture: res = new ScreenCaptureAction(options as ScreenCaptureOptions, GUID); break; case ActionTypes.KillProcess: res = new KillProcessAction(options as KillProcessOptions, GUID); break; case ActionTypes.DeleteFiles: res = new DeleteFilesAction(options as DeleteFilesOptions, GUID); break; case ActionTypes.CycleProfile: res = new CycleProfileAction(options as CycleProfileOptions, GUID); break; case ActionTypes.ShowHideProcess: res = new ShowHideProcessAction(options as AddOptions.ShowHideProcessOptions, GUID); break; default: throw new ArgumentException($"DEV ERROR: could not create key action from factory of type {type}."); } return(res); }
//public KeyboardShortcut() { } /// <summary> /// Create a keyboard shortcut entry. /// </summary> /// <param name="combination">The key combination needed, if any, for activating this shortcut.</param> /// <param name="key">The specific key that corresponds to this shortcut.</param> /// <param name="action">The action to perform when this shortcut is activated.</param> public KeyboardShortcut(KeyboardCombination combination, Key key, IKeyAction action) { Combination = combination; Key = key; Action = action; MethodId = action.ID; GenerateKeyString(); SourceElement = action.SourceElement; }
private void CreateAddForm(IKeyAction selectedAction) { if (AddForm == null && ProfileForm == null && Data.ProfileNames.Any()) { EnableDisableControls(false); HookManager.CleanHook(); AddForm = new Add(Data, selectedAction); AddForm.StartPosition = FormStartPosition.Manual; AddForm.Location = new Point((this.Location.X + this.Width / 2) - Add.DIMENSIONS_DEFAULT.X / 2, this.Location.Y); AddForm.FormClosed += new FormClosedEventHandler(AddFormClosed); AddForm.Show(); } }
private IKeyAction ResolveSelectedKeyAction() { IKeyAction res = null; try { if (listView1.SelectedItems.Count > 0) { var selectedGUID = listView1.SelectedItems[0].Tag.ToString(); if (Data.SelectedActionMap != null && Data.SelectedActionMap.ContainsKey(selectedGUID)) { res = Data.SelectedActionMap[selectedGUID]; } } } catch { res = null; } return(res); }
public static IKeyAction GetKeyActionFromPropertyMap(Dictionary <string, string> propertyMap) { IKeyAction res = null; ActionTypes type = (ActionTypes)Enum.Parse(typeof(ActionTypes), propertyMap["Type"], true); switch (type) { case ActionTypes.OpenProcess: res = new OpenProcessAction(propertyMap); break; case ActionTypes.ScreenCapture: res = new ScreenCaptureAction(propertyMap); break; case ActionTypes.KillProcess: res = new KillProcessAction(propertyMap); break; case ActionTypes.DeleteFiles: res = new DeleteFilesAction(propertyMap); break; case ActionTypes.CycleProfile: res = new CycleProfileAction(propertyMap); break; case ActionTypes.ShowHideProcess: res = new ShowHideProcessAction(propertyMap); break; default: throw new ArgumentException($"DEV ERROR: could not create key action from factory of type {type}."); } return(res); }
/// <summary> /// Load a list of keyboard shortcuts from a file. The list of available actions is also needed to map the shortcuts to these actions. /// </summary> /// <param name="file">The file to load from.</param> /// <param name="list">A list of actions available to be accessed via keyboard shortcuts.</param> /// <returns>A list of keyboard shortcuts, which can be loaded into a KeyRegistry.</returns> /// <exception cref="FileNotFoundException">Thrown if the file does not exist.</exception> /// <remarks>If there is a shortcut in this file that reference an action ID that isn't on the <paramref name="list"/>, then that shortcut is skipped.</remarks> public static List <KeyboardShortcut> LoadFromFile(string file, KeyActionList list) { if (!File.Exists(file)) { throw new FileNotFoundException("The specified file does not exist. Keyboard shortcuts cannot be loaded.", file); } List <KeyboardShortcut> entries = new List <KeyboardShortcut>(); XmlReader xr = XmlReader.Create(file); xr.MoveToContent(); while (xr.Read()) { if (xr.NodeType == XmlNodeType.Element) { //xr.ReadStartElement("ks"); #if NETCOREAPP string?c = xr.GetAttribute("comb"); string?k = xr.GetAttribute("keyid"); string?m = xr.GetAttribute("action"); #else string c = xr.GetAttribute("comb"); string k = xr.GetAttribute("keyid"); string m = xr.GetAttribute("action"); #endif if (string.IsNullOrEmpty(m)) { m = xr.GetAttribute("methodid"); } if (string.IsNullOrEmpty(c) || string.IsNullOrEmpty(k) || string.IsNullOrEmpty(m)) { // skip item } else if (Enum.TryParse(c, out KeyboardCombination kc)) { // try to load keys by their internal integer value // from https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.key?view=net-5.0 (the middle column) if (int.TryParse(k, out int kv)) { #if NETCOREAPP IKeyAction?a = null; #else IKeyAction a = null; #endif if (list != null) { // checks the key action list for "Xxx", "mnuXxx", and "btnXxx" // this is a carryover from internal usage, but I figure it should still be helpful // if desired, I can remove this or make a toggle for it in a future release if (list.ContainsId(m)) { a = list[m]; } else if (list.ContainsId("mnu" + m)) { m = "mnu" + m; a = list[m]; } else if (list.ContainsId("btn" + m)) { m = "btn" + m; a = list[m]; } } if (a != null) { KeyboardShortcut ke = new KeyboardShortcut(kc, (Key)kv, a); entries.Add(ke); } } else { // if the integer-based value doesn't work, try to parse based upon the name of the Key in the enum // again from https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.key?view=net-5.0 (the left column) if (Enum.TryParse(k, out Key kz)) { #if NETCOREAPP IKeyAction?a = null; #else IKeyAction a = null; #endif if (list != null) { // checks the key action list for "Xxx", "mnuXxx", and "btnXxx" // this is a carryover from internal usage, but I figure it should still be helpful // if desired, I can remove this or make a toggle for it in a future release if (list.ContainsId(m)) { a = list[m]; } else if (list.ContainsId("mnu" + m)) { m = "mnu" + m; a = list[m]; } else if (list.ContainsId("btn" + m)) { m = "btn" + m; a = list[m]; } } if (a != null) { KeyboardShortcut ke = new KeyboardShortcut(kc, kz, a); entries.Add(ke); } } } } //xr.ReadEndElement(); } } xr.Close(); return(entries); }
/// <summary> /// Custom key-map /// </summary> /// <param name="key"></param> /// <param name="action"></param> public static void RegisterKeyAction(ConsoleKey key, IKeyAction action) { KeyActions[key] = action ?? throw new NullReferenceException("Key action is required NOT NULL"); action?.OnRegist(ctx); }
public void AddKeyAction(IKeyAction action) { keyActions.Add(action); }