Beispiel #1
0
        public static IntPtr CallbackFunction(Int32 code, IntPtr wParam, IntPtr lParam)
        {
            WM eventType = (WM)wParam;

            if (code >= 0 && (eventType == WM.KEYDOWN || eventType == WM.KEYUP || eventType == WM.SYSKEYDOWN || eventType == WM.SYSKEYUP))
            {
                //Task.Run(async() => { await Task.Run(() => { AppManager.GetAppManager().CheckIfSessionChanged(); }); });
                var logMngr = GetKeyStrokesManager();
                if (AppManager.GetAppManager().IsBusy == true)
                {
                    return(NativeMethods.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
                }
                AppManager.GetAppManager().CheckIfSessionChanged();
                KBDLLHOOKSTRUCT keyData        = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                var             vKey           = keyData.vkCode;
                KeystrokeEvent  keystrokeEvent = new KeystrokeEvent();
                keystrokeEvent.EventTime = keyData.time;
                Keys defaultKeysEnum = (Keys)vKey;
                var  key             = KeyMapper.GetKeyEnum(defaultKeysEnum);
                if (key == KeysList.NoKey)
                {
                    return(NativeMethods.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
                }
                keystrokeEvent.Key.Data = key;
                if (eventType == WM.KEYDOWN || eventType == WM.SYSKEYDOWN)
                {
                    keystrokeEvent.Type = KeystrokeType.KeyDown;
                    //Console.WriteLine("Down");
                }
                else if (eventType == WM.KEYUP || eventType == WM.SYSKEYUP)
                {
                    TimeManager.GetTimeManager().CreateNewAction();
                    keystrokeEvent.Type = KeystrokeType.KeyUp;
                    //Console.WriteLine("Up");
                }
                logMngr.InsertKeystrokeEvent(keystrokeEvent);
                //Console.WriteLine($"{btnStatus},{keyData.time},{defaultKeysEnum.GetDescription()}, {key.GetDescription()}");
            }
            return(NativeMethods.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
        }