// 安装钩子
        public void KeyMaskStart()
        {
            if (hKeyboardHook == 0)
            {
                // 创建HookProc实例
                KeyboardHookProcedure = new KeyboardProc(KeyboardHookProc);

                var modules = Assembly.GetExecutingAssembly().GetModules();

                // 设置线程钩子
                hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProcedure,
                    //Marshal.GetHINSTANCE(modules[0]), 0);
                    IntPtr.Zero, 0);

                // 如果设置钩子失败
                if (hKeyboardHook == 0)
                {
                    KeyMaskStop();
                    throw new Exception("SetWindowsHookEx failed.");
                }
                ////用二进制流的方法打开任务管理器。而且不关闭流.这样任务管理器就打开不了
                //MyFs = new FileStream(Environment.ExpandEnvironmentVariables("%windir%\\system32\\taskmgr.exe"),
                //FileMode.Open);
                //byte[] MyByte = new byte[(int)MyFs.Length];
                //MyFs.Write(MyByte, 0, (int)MyFs.Length);
            }
        }
        static IntPtr SetHook(KeyboardProc proc)
        {
#pragma warning disable 618
            return(SetWindowsHookEx(WH_KEYBOARD, proc, IntPtr.Zero, (uint)AppDomain.GetCurrentThreadId()));

#pragma warning restore 618
        }
Beispiel #3
0
 private static IntPtr SetHook(KeyboardProc proc)
 {
     using (var process = Process.GetCurrentProcess())
         using (var module = process.MainModule)
         {
             return(SetWindowsHookEx(WhKeyboardLl, proc, GetModuleHandle(module?.ModuleName), 0));
         }
 }
Beispiel #4
0
 private IntPtr SetHook(KeyboardProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx(WH_KEYBOARD_LL, proc,
                                     GetModuleHandle(curModule.ModuleName), 0));
         }
 }
 public static IntPtr SetHook(KeyboardProc proc)
 {
     using (var process = Process.GetCurrentProcess())
     {
         using (var module = process.MainModule)
         {
             return(SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(module.ModuleName), 0));
         }
     }
 }
Beispiel #6
0
		public Hook(IMessageHandlerClient client)
		{
			m_Client=client;
			m_mouseHook = new MouseProc(OnMouseHook);
			m_keyboardHook=new KeyboardProc(OnKeyboardHook);
			m_hMouseHook = SetWindowsHookEx(WH_MOUSE, m_mouseHook, IntPtr.Zero, GetCurrentThreadId());
			m_hKeyboardHook=SetWindowsHookExKeyboard(WH_KEYBOARD,m_keyboardHook,IntPtr.Zero,GetCurrentThreadId());
			if (m_hMouseHook == IntPtr.Zero || m_hKeyboardHook==IntPtr.Zero)
			{
				throw new Win32Exception();
			}
		}
 public void HookKeyboard(MainWindow _mainWindow)
 {
     mainWindow = _mainWindow;
     registeredKeyboardProc = MyKeyboardProc;
     using (Process curProcess = Process.GetCurrentProcess())
     {
         using (ProcessModule curModule = curProcess.MainModule)
         {
             hookId = SetWindowsHookEx(HookType.WH_KEYBOARD_LL, registeredKeyboardProc, GetModuleHandle(curModule.ModuleName), 0);
         }
     }
 }
Beispiel #8
0
        private static IntPtr AttachKeyboardHook(KeyboardProc proc)
        {
            using (var process = Process.GetCurrentProcess())
            {
                using (var processModule = process.MainModule)
                {
                    var hook = SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(processModule.ModuleName),
                                                0);

                    return(hook);
                }
            }
        }
Beispiel #9
0
 public void Hook()
 {
     if (hookId == IntPtr.Zero)
     {
         proc = HookProcedure;
         using (var curProcess = Process.GetCurrentProcess())
         {
             using (ProcessModule curModule = curProcess.MainModule)
             {
                 hookId = SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
             }
         }
     }
 }
Beispiel #10
0
 public void Hook()
 {
     if (this.hookId == IntPtr.Zero)
     {
         proc = HookProcedure;
         using (var curProcess = Process.GetCurrentProcess())
         {
             using (ProcessModule curModule = curProcess.MainModule)
             {
                 this.hookId = SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
                 Logger.WriteLine($"AbstractInterceptKeyboard.SetHookWindowsHookEx = {hookId}");
             }
         }
     }
 }
Beispiel #11
0
		private static extern IntPtr SetWindowsHookExKeyboard(int hookid, KeyboardProc pfnhook, IntPtr hinst, int threadid);
Beispiel #12
0
 private static extern IntPtr SetWindowsHookEx(int idHook,
                                               KeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
Beispiel #13
0
 static extern IntPtr SetWindowsHookEx(int idHook, KeyboardProc lpfn, IntPtr hInstance, int threadId);
 private IntPtr SetHook(KeyboardProc proc)
 {
     try
     {
         using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return SetWindowsHookEx(WH_KEYBOARD_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
         }
     }
     catch(Exception ex)
     {
         Log.Add(ex);
     }
     return new IntPtr();
 }
 private static extern IntPtr SetWindowsHookEx(int idHook, KeyboardProc callback, IntPtr hInstance, uint threadId);
 private static extern IntPtr SetWindowsHookEx(int idHook, KeyboardProc callback, IntPtr hInstance, uint threadId);
Beispiel #17
0
 private static extern IntPtr SetWindowsHookEx(int hookId, KeyboardProc callbackFunction, IntPtr moduleHandle, uint threadId);
 static extern IntPtr SetWindowsHookEx(HookType idHook, KeyboardProc lpfn, IntPtr hMod, int dwThreadId);
Beispiel #19
0
 internal static extern int SetWindowsHookEx(int idHook, KeyboardProc lpfn, IntPtr hInstance, int threadId);
Beispiel #20
0
 static IntPtr SetHook(KeyboardProc proc)
 {
     #pragma warning disable 618
     return SetWindowsHookEx(WH_KEYBOARD, proc, IntPtr.Zero, (uint) AppDomain.GetCurrentThreadId());
     #pragma warning restore 618
 }
 public KeyboardHook()
 {
     proc = HookCallback;
 }
 private static extern IntPtr SetWindowsHookEx(int idHook, KeyboardProc lpfn, IntPtr hMod, uint dwThreadId);
Beispiel #23
0
 public void InitKeyboardCapture()
 {
     KeyHandler   = null;
     KeyHandler  += KeyCallback;
     kbHookHandle = SetWindowsHookEx(2, KeyHandler, IntPtr.Zero, (int)GetCurrentThreadId());
 }
Beispiel #24
0
        internal void KeyMaskStart(Func<bool> callback)
        {
            _callback = callback;
            if (hKeyboardHook == 0)
            {
                // 创建HookProc实例
                KeyboardHookProcedure = new KeyboardProc(KeyboardHookProc);

                // 设置线程钩子
                hKeyboardHook = NativeMethods.SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProcedure,
                    NativeMethods.GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), 0);
                // 如果设置钩子失败
                if (hKeyboardHook == 0)
                {
                    KeyMaskStop();
                    throw new Exception("SetWindowsHookEx failed.");
                }
                ////用二进制流的方法打开任务管理器。而且不关闭流.这样任务管理器就打开不了
                //MyFs = new FileStream(Environment.ExpandEnvironmentVariables("%windir%\\system32\\taskmgr.exe"),
                //FileMode.Open);
                //byte[] MyByte = new byte[(int)MyFs.Length];
                //MyFs.Write(MyByte, 0, (int)MyFs.Length);
            }
        }
 public static extern IntPtr SetWindowsHookEx(int id, KeyboardProc proc, IntPtr mod, uint thread);
Beispiel #26
0
 private static extern IntPtr SetWindowsHookEx(int hookId, KeyboardProc callbackFunction, IntPtr moduleHandle, uint threadId);