public bool Test(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args) { if (args.Length < 1 || !(args[0] is string processname)) { return(false); } IntPtr hwnd = Program.ForegroundWindow; try { GetWindowThreadProcessId(hwnd, out int pid); Process p = Process.GetProcessById(pid); bool match = p.ProcessName.Length == processname.Length && p.ProcessName.Equals(processname, StringComparison.InvariantCultureIgnoreCase); if (match && args.Length > 1 && args[1] is string classname) { string hwndclass = GetClassNameOfWindow(hwnd); match = hwndclass != null && classname.Length == hwndclass.Length && classname.Equals(hwndclass, StringComparison.InvariantCultureIgnoreCase); } return(match); } catch { } return(false); }
internal Keybind Add(MainForm parent, KeybindDevice device, Keybind clone = null) { Configuring = true; AddEditButton.Text = "Add as new keybind"; return(Edit(parent, device, clone ?? null)); }
public bool Perform(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args) { if (args.Length < 1 || !(args[0] is string processname)) { return(false); } List <IntPtr> windows = new List <IntPtr>(); string classname = args.Length > 1 && args[1] is string cn ? cn : null; Process[] processes = Process.GetProcessesByName(processname); foreach (Process p in processes) { foreach (ProcessThread t in p.Threads) { EnumThreadWindows(t.Id, (hwnd, lParam) => { if (string.IsNullOrEmpty(classname)) { windows.Add(hwnd); return(true); } string hwndclass = GetClassNameOfWindow(hwnd); if (hwndclass != null && hwndclass.Length == classname.Length && hwndclass.Equals(classname, StringComparison.InvariantCultureIgnoreCase)) { windows.Add(hwnd); } return(true); }, ""); } } Dictionary <int, IntPtr> Zorder = new Dictionary <int, IntPtr>(); foreach (IntPtr hwnd in windows) { int z = GetWindowZOrder(hwnd); if (z == -1) { continue; } Zorder[z] = hwnd; } RestoreWindow(Zorder.OrderBy(kv => kv.Key).ElementAt(Zorder.Count - 1).Value); return(true); }
public DeviceListViewItem(KeybindDevice device) : base() { Device = device; Text = $"{(Device.Connected ? "" : "[Unplugged] ")}{Device.Name}"; SubItems.AddRange(new ListViewSubItem[] { new ListViewSubItem(this, Device?.ID) { Name = "ID" }, }); }
public bool TestCondition(KeybindDevice device, Keys key, KeyState state, KeyState lastState) { try { return(Condition == null || Condition.Test(device, key, state, lastState, GUID, ConditionArgs ?? new object[0])); } catch (Exception e) { Console.WriteLine($"Error executing ICondition type \"{ConditionTypeName}\":\r\n{e}"); SystemSounds.Exclamation.Play(); return(false); } }
public bool Perform(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args) { if (args.Length < 1 || !(args[0] is string path) || string.IsNullOrWhiteSpace(path) || !Directory.Exists(path)) { return(false); } path = path.Replace("/", "\\").TrimEnd('\\'); IntPtr hwnd = IntPtr.Zero; ShellWindows shellWindows = new ShellWindows(); foreach (InternetExplorer ie in shellWindows) { if (!Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("explorer")) { continue; } try { string folderpath = new Uri(ie.LocationURL).LocalPath; if (folderpath == path) { hwnd = (IntPtr)ie.HWND; break; } } catch { } } if (hwnd == IntPtr.Zero) { Process.Start(path); } else { RestoreWindow(hwnd); } return(true); }
public bool Perform(KeybindDevice device, Keys key, KeyState state, KeyState lastState, string guid, params object[] args) { if (args.Length < 1 || !(args[0] is string path)) { return(false); } try { Process.Start(path, args.Length > 1 && args[1] is string arguments ? arguments : ""); return(true); } catch { } return(false); }
public bool PerformMacro(KeybindDevice device, Keys key, KeyState state, KeyState lastState, bool testCondition = false) { try { if (testCondition && !TestCondition(device, key, state, lastState)) { return(false); } return(Macro == null || Macro.Perform(device, key, state, lastState, GUID, MacroArgs ?? new object[0])); } catch (Exception e) { Console.WriteLine($"Error executing IMacro type \"{MacroTypeName}\":\r\n{e}"); SystemSounds.Exclamation.Play(); return(false); } }
public static KeybindDevice Load(string deviceIDfile) { string folder = Path.Combine(Program.Location, "Keybinds"); Directory.CreateDirectory(folder); string file = Path.Combine(folder, deviceIDfile); KeybindDevice device = File.Exists(file) ? JsonConvert.DeserializeObject <KeybindDevice>(File.ReadAllText(file)) : null; if (device != null) { foreach (Keybind keybind in device.Keybinds) { keybind.Device = device; } } return(device); }
internal Keybind Edit(MainForm parent, KeybindDevice device, Keybind keybind) { if (!Configuring) { AddEditButton.Text = "Confirm changes"; } Configuring = true; Device = device; Keybind = keybind == null ? new Keybind() : new Keybind(keybind.Name, keybind.Keys.ToList(), keybind.Condition, keybind.ConditionArgs, keybind.Macro, keybind.MacroArgs) { Device = Device, Enabled = keybind.Enabled, MatchKeysOrder = keybind.MatchKeysOrder, ActivateOnKeyDown = keybind.ActivateOnKeyDown, ActivateOnHold = keybind.ActivateOnHold, ActivateOnKeyUp = keybind.ActivateOnKeyUp, ActivateIfMoreKeysPressed = keybind.ActivateIfMoreKeysPressed, AllowOtherKeybinds = keybind.AllowOtherKeybinds, }; NameTextBox.Text = Keybind.Name ?? ""; NameTextBox.Select(); EnabledCheckBox.Checked = Keybind.Enabled; UpdateKeys(); ActivateOnKeyDownCheckBox.Checked = Keybind.ActivateOnKeyDown; ActivateOnHoldCheckBox.Checked = Keybind.ActivateOnHold; ActivateOnKeyUpCheckBox.Checked = Keybind.ActivateOnKeyUp; ActivateIfMoreKeysPressedCheckBox.Checked = Keybind.ActivateIfMoreKeysPressed; UpdateCondition(); ConditionArgsListBox.Items.Clear(); if (Keybind.ConditionArgs != null) { foreach (object arg in Keybind.ConditionArgs) { ConditionArgsListBox.Items.Add(arg); } } ConditionArgTypeComboBox.SelectedIndex = 0; UpdateMacro(); MacroArgsListBox.Items.Clear(); if (Keybind.MacroArgs != null) { foreach (object arg in Keybind.MacroArgs) { MacroArgsListBox.Items.Add(arg); } } MacroArgTypeComboBox.SelectedIndex = 0; AllowOtherKeybindsCheckBox.Checked = Keybind.AllowOtherKeybinds; Configuring = false; CheckCanSave(); if (ShowDialog(parent) == DialogResult.Cancel) { Keybind = null; } return(Keybind); }