Exemple #1
0
        public static HookKeyEventArgs Copy(HookKeyEventArgs hookKeyEvent)
        {
            var newEvent = new HookKeyEventArgs();

            newEvent.Key            = hookKeyEvent.Key;
            newEvent.InputKeyType   = hookKeyEvent.InputKeyType;
            newEvent.EventTimeStamp = hookKeyEvent.EventTimeStamp;
            newEvent.InputString    = hookKeyEvent.InputString;
            return(newEvent);
        }
Exemple #2
0
        protected override int HookCallbackProcedure(int nCode, int wParam, IntPtr lParam)
        {
            bool handled = false;

            if (nCode > -1 && (KeyLog != null))
            {
                KeyboardHookStruct keyboardHookStruct =
                    (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));

                var key     = KeyInterop.KeyFromVirtualKey(keyboardHookStruct.vkCode);
                var hookKey = new HookKeyEventArgs()
                {
                    InputKeyType   = GetKeyType(wParam),
                    Key            = key,
                    EventTimeStamp = DateTime.Now
                };
                KeyLog(this, hookKey);
            }
            return(CallNextHookEx(_handleToHook, nCode, wParam, lParam));
        }