Пример #1
0
 private static IntPtr SetHook(NativeMethods.LowLevelKeyboardProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(NativeMethods.SetWindowsHookEx(NativeMethods.WH_KEYBOARD_LL, proc, NativeMethods.GetModuleHandle(curModule.ModuleName), 0));
         }
 }
 /// <summary>
 /// Disposes resources in use.
 /// </summary>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         LowLevelKeyboardProcedure = null; //let GC collect it now
     }
     Unhook();
 }
Пример #3
0
        public KernelKeyRecorder()
        {
            KeyChannel       = Channel.CreateUnbounded <string>();
            KeyChannelReader = KeyChannel.Reader;
            KeyChannelWriter = KeyChannel.Writer;

            KeyboardHookProc = KeyboardProc;
        }
Пример #4
0
 public static IntPtr SetHook(NativeMethods.LowLevelKeyboardProc keyboardCallback)
 {
     using (Process proc = Process.GetCurrentProcess()) {
         using (var procModule = proc.MainModule) {
             return(NativeMethods.SetWindowsHookEx(
                        Constants.whl_keyboard_ll, keyboardCallback, NativeMethods.GetModuleHandle(procModule.ModuleName), 0
                        ));
         }
     }
 }
Пример #5
0
        public void Start()
        {
            if (_hook != IntPtr.Zero)
            {
                return;
            }

            using (var process = Process.GetCurrentProcess())
            using (var module = process.MainModule)
            {
                _keyboardHookProc = KeyboardHookProc;

                _hook = NativeMethods.SetWindowsHookEx(Consts.WH_KEYBOARD_LL, _keyboardHookProc, NativeMethods.GetModuleHandle(module.ModuleName), 0);
            }
        }
Пример #6
0
        public KeyLogger()
        {
            logger.Info("Logging started at {0}", DateTime.Now.ToLongTimeString());

            InitializeComponent();

            this.keyBuffer = new StringBuilder();
            this.lastKeyDown = DateTime.MinValue;
            this.keyboardCallback = new NativeMethods.LowLevelKeyboardProc(this.HookCallback);
            this.keyboardHookId = SetHook(keyboardCallback);

            Microsoft.Win32.SystemEvents.SessionEnding += SystemEvents_SessionEnding;

            logger.Debug("Hook ID {0}", this.keyboardHookId.ToString());
        }
Пример #7
0
        public void Start()
        {
            if (_hook != IntPtr.Zero)
            {
                return;
            }

            using (var process = Process.GetCurrentProcess())
                using (var module = process.MainModule)
                {
                    _keyboardHookProc = KeyboardHookProc;

                    _hook = NativeMethods.SetWindowsHookEx(Consts.WH_KEYBOARD_LL, _keyboardHookProc, NativeMethods.GetModuleHandle(module.ModuleName), 0);
                }
        }
        /// <summary>
        /// Starts the keyboard hook.
        /// </summary>
        /// <exception cref="Win32Exception"></exception>
        public void Hook()
        {
            if (HookHandle.IsInvalid || HookHandle.IsClosed)
            {
                if (LowLevelKeyboardProcedure == null)   //needs to be in variable so GC doesn't collect it
                {
                    LowLevelKeyboardProcedure = new NativeMethods.LowLevelKeyboardProc(KeyboardHookProc);
                }
                HookHandle = NativeMethods.SetWindowsHookEx(
                    idHook: NativeMethods.WH_KEYBOARD_LL,
                    lpfn: LowLevelKeyboardProcedure,
                    hMod: IntPtr.Zero,
                    dwThreadId: 0);

                if (HookHandle.IsInvalid)
                {
                    throw new Win32Exception();
                }
            }
        }
Пример #9
0
        public HumanInterfaceDeviceMonitor()
        {
            hookThread = new Thread(new ThreadStart(() =>
            {
                keyboardProc   = HookCallback;
                keyboardHookID = SetHook(keyboardProc);

                mouseProc   = MouseHook;
                mouseHookID = SetHook(mouseProc);

                hookThreadApplicationContext = new ApplicationContext();
                Application.Run(hookThreadApplicationContext);
            }))
            {
                Name = "HumanInterfaceDeviceMonitor.hookThread"
            };

            hookThread.SetApartmentState(ApartmentState.STA);

            hookThread.Start();
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the KeyboardHook class.
 /// </summary>
 public KeyboardHook()
 {
     hookCallback = HookCallBack;
     Combination  = new KeyCombination(KeysEx.None);
 }
Пример #11
0
        private HotKeyGlobalLL()
            : base(IntPtr.Zero, true) {

            _callback = new NativeMethods.LowLevelKeyboardProc(LowLevelKeyboardCallBack);
            this.handle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_KEYBOARD_LL, _callback, IntPtr.Zero, 0);
        }
Пример #12
0
 private KeyboardHook()
 {
     keyboardProc = HookCallback;
     hookId       = SetHook(keyboardProc);
 }
Пример #13
0
 private HotKeyGlobalLL()
     : base(IntPtr.Zero, true)
 {
     _callback   = new NativeMethods.LowLevelKeyboardProc(LowLevelKeyboardCallBack);
     this.handle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_KEYBOARD_LL, _callback, IntPtr.Zero, 0);
 }
Пример #14
0
		/// <summary>
		/// Initializes a new instance of the KeyboardHook class.
		/// </summary>
		public KeyboardHook()
		{
			hookCallback = HookCallBack;
			Combination = new KeyCombination(KeysEx.None);
		}