// finds and uses a key macro private bool FindKeyMacro(int vk, bool isDown) { bool passKey = true; ModifierKey modifiers = Macro.GetCurrentModifierKeys(vk); foreach (Trigger trig in macro_table.Keys) { if (trig.CanTrigger(isDown, vk, modifiers)) { CompiledMacro macro = macro_table[trig]; if (macro.TimeSinceLastRun > settings._macroActivationDelay) { macro.Execute(); } if (macro.HasTableSwitch) { SwitchMacroTable(macro.TableSwitchIdx); } // Only pass if the key was not already down. Otherwise, use macro.passOriginalKey passKey = macro.PassOriginalKey; if (isDown) { prevMacroVk = vk; } break; } } bool tempResult = passKey && (isDown ^ IsKeyDepressed(vk)); //System.Diagnostics.Debug.WriteLine(Macro.GetKeyString(vk, ModifierKey.None) + ": " + tempResult.ToString()); return(tempResult); //let it pass }
private void CompileAll() { page_dicts.Clear(); foreach (MacroPage page in _macroPages) { Dictionary <Trigger, CompiledMacro> next_table = new Dictionary <Trigger, CompiledMacro> (); foreach (Macro member in page.macros) { if (!member.HasTriggers) { continue; } foreach (Trigger trig in member.Triggers) { CompiledMacro next = member.Compile(trig); if (next.HasTableSwitch) { next.TableSwitchIdx = _macroPages.FindIndex((p) => (p.name.Equals(next.TableSwitchName))); } // That line above has n^2 complexity and completely f***s up if the page table is non existant. // It finds the index within page_dicts to switch to. if (!next_table.ContainsKey(trig)) { next_table.Add(trig, next); } } } page_dicts.Add(next_table); } // Yes we start on the FIRST PAGE not not a default index. macro_table = page_dicts[_defaultPageIdx]; }
private bool _mouseDown(MouseButtons btn, Hooker.MouseLLHookStruct evt) { if (DisableCondition()) { return(true); } if (evt.IsInjected) { return(true); } bool passKey = true; foreach (Trigger trig in macro_table.Keys) { /* System.Diagnostics.Debug.WriteLine(trig.processName.FirstOrDefault() + " " + evt.Point.X + " " + evt.Point.Y);*/ if (trig.CanTrigger(true, evt.Point.X, evt.Point.Y, btn, ModifierKey.None)) //assert here trig.vk == vk. { CompiledMacro macro = macro_table[trig]; //listView1.Items.Add(macro._events[0].Data.Keyboard.Flags.ToString());//DEBUG macro.Execute(); if (macro.HasTableSwitch) { macro_table = page_dicts[macro.TableSwitchIdx]; BeginInvoke((MethodInvoker) delegate { txtCurrentPage.Text = "Switched to " + _macroPages[macro.TableSwitchIdx].name;//DEBUG UpdateOSD(_macroPages[macro.TableSwitchIdx].name, macro.TableSwitchIdx); }); } // passKey = macro.PassOriginalKey;//DO NOT ALLOW MOUSE SUPRESS INPUT break; } } return(passKey); }
// --------------- Mouse event handler //Note - it's not gonna be injected since as of now we cannot support mouse inputs. private bool _mouseUp(MouseButtons btn, Hooker.MouseLLHookStruct evt) { if (DisableCondition()) { return(true); } if (evt.IsInjected) { return(true); } bool passKey = true; foreach (Trigger trig in macro_table.Keys) { if (trig.CanTrigger(false, evt.Point.X, evt.Point.Y, btn, ModifierKey.None)) //NOTE - NO SUPPORT FOR MOUSE MOdIFIERS! { CompiledMacro macro = macro_table[trig]; //listView1.Items.Add(macro._events[0].Data.Keyboard.Flags.ToString());//DEBUG macro.Execute(); if (macro.HasTableSwitch) { macro_table = page_dicts[macro.TableSwitchIdx]; BeginInvoke((MethodInvoker) delegate { txtCurrentPage.Text = "Switched to " + _macroPages[macro.TableSwitchIdx].name;//DEBUG UpdateOSD(_macroPages[macro.TableSwitchIdx].name, macro.TableSwitchIdx); }); } // passKey = macro.PassOriginalKey; break; } } return(passKey); }