/// <summary> /// Sets multiple hooks. /// </summary> /// <exception cref="InvalidOperationException">Hooks are already set and <see cref="Unhook"/> not called.</exception> /// <remarks> /// Parameters are the same as of the constructor, but values can be different. /// </remarks> public void Hook(AccEVENT[] events, int idProcess = 0, int idThread = 0, AccHookFlags flags = 0) { _Throw1(); _a = new IntPtr[events.Length]; for (int i = 0; i < events.Length; i++) { _SetHook(i, events[i], 0, idProcess, idThread, flags); } }
/// <summary> /// Sets a hook for an event or a range of events. /// </summary> /// <exception cref="InvalidOperationException">Hooks are already set and <see cref="Unhook"/> not called.</exception> /// <remarks> /// Parameters are the same as of the constructor, but values can be different. /// </remarks> public void Hook(AccEVENT eventMin, AccEVENT eventMax = 0, int idProcess = 0, int idThread = 0, AccHookFlags flags = 0) { _Throw1(); _a = new IntPtr[1]; _SetHook(0, eventMin, eventMax, idProcess, idThread, flags); }
/// <summary> /// Sets multiple hooks. /// </summary> /// <param name="events">Events. Reference: API <msdn>SetWinEventHook</msdn>. Elements with value 0 are ignored.</param> /// <param name="hookProc">The hook procedure (function that handles hook events).</param> /// <param name="idProcess">The id of the process from which the hook function receives events. If 0 - all processes on the current desktop.</param> /// <param name="idThread">The native id of the thread from which the hook function receives events. If 0 - all threads.</param> /// <param name="flags"></param> /// <exception cref="AuException">Failed.</exception> /// <example>See <see cref="AHookAcc"/>.</example> public AHookAcc(AccEVENT[] events, Action <HookData.AccHookData> hookProc, int idProcess = 0, int idThread = 0, AccHookFlags flags = 0) { _proc1 = _HookProc; Hook(events, idProcess, idThread, flags); _proc2 = hookProc; }
void _SetHook(int i, AccEVENT eMin, AccEVENT eMax, int idProcess, int idThread, AccHookFlags flags) { if (eMin == 0) { return; } if (eMax == 0) { eMax = eMin; } var hh = Api.SetWinEventHook(eMin, eMax, default, _proc1, idProcess, idThread, flags);