/// <summary> /// HookCallbackAsync procedure that calls accordingly the KeyDown or KeyUp events. /// </summary> /// <param name="keyEvent">Keyboard event</param> /// <param name="vkCode">VKCode</param> /// <param name="character">Character as string.</param> void KeyboardListener_KeyboardCallbackAsync(WinAPI.KeyEvent keyEvent, int vkCode, string character, DateTime dateTime, WindowHandle windowHandle, uint processID) { string processName = GetProcessName(processID); StringBuilder windowTitle = new StringBuilder(MaxTitleSize); WinAPI.GetWindowText(windowHandle, windowTitle, MaxTitleSize); var eventArgs = new RawKeyEventArgs(vkCode, character, DateTime.Now, processID, processName, windowHandle, windowTitle.ToString()); if (keyEvent == WinAPI.KeyEvent.WM_KEYDOWN || keyEvent == WinAPI.KeyEvent.WM_SYSKEYDOWN) { KeyDown?.BeginInvoke(this, eventArgs, null, null); } else if (keyEvent == WinAPI.KeyEvent.WM_KEYUP || keyEvent == WinAPI.KeyEvent.WM_SYSKEYUP) { KeyUp?.BeginInvoke(this, eventArgs, null, null); } }