Exemple #1
0
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process currentProcess = Process.GetCurrentProcess())
     {
         using (ProcessModule currentModule = currentProcess.MainModule)
             return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(currentModule.ModuleName), 0);
     }
 }
Exemple #2
0
 /// <summary>
 /// Get Current Process and Module and Installs an application-defined hook procedure into a hook chain. You would install a hook procedure to monitor the system for certain types of events. These events are associated either with a specific thread or with all threads in the same desktop as the calling thread
 /// </summary>
 /// <param name="proc">HookCallback</param>
 /// <returns></returns>
 public static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (var curProcess = Process.GetCurrentProcess())
     using (var curModule = curProcess.MainModule)
     {
         return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
     }
 }
Exemple #3
0
        //Apply Singleton Design END

        public void Hook()
        {
            using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    _proc   = HookCallback;
                    _hookID = SetWindowsHookEx(WH_MOUSE_LL, _proc, GetModuleHandle(curModule.ModuleName), 0);
                }
        }
Exemple #4
0
        public Hook(LowLevelMouseProc callback)
        {
            this._Callback = GCHandle.Alloc(callback);

            if ((this._Handle = NativeMethods.SetWindowsHookExW(NativeMethods.WH_MOUSE_LL, Marshal.GetFunctionPointerForDelegate(callback), NativeMethods.GetModuleHandle(), 0)) == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
Exemple #5
0
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     // http://stackoverflow.com/questions/11607133/global-mouse-event-handler
     // SetWindowsHookEx() requires a valid module handle but doesn't actually use it when you
     // set a low-level mouse hook. So any handle will do, you can pass the handle for user32.dll,
     // always loaded in a .NET application
     return(MouseHook.SetWindowsHookEx(WH_MOUSE_LL, proc,
                                       MouseHook.GetModuleHandle("user32"), 0));
 }
Exemple #6
0
 private static IntPtr SetMouseHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             return(SetWindowsHookEx(WH_MOUSE_LL, proc,
                                     GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Exemple #7
0
        public Hook(LowLevelMouseProc callback)
        {
            this._Callback = GCHandle.Alloc(callback);

            if ((this._Handle = NativeMethods.SetWindowsHookExW(NativeMethods.WH_MOUSE_LL, Marshal.GetFunctionPointerForDelegate(callback), NativeMethods.GetModuleHandle(), 0)) == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
        }
Exemple #8
0
 /*SetWindowsHookEx to install a hook to an event: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-setwindowshookexa
  **"proc" is the callback when the event happens, the signature is described here: https://msdn.microsoft.com/en-us/library/ms644986(v=VS.85).aspx
  ** Returns:
  **      Hook pointer neded for releasing the hook or handling callbacks
  */
 public static IntPtr registerLowLevelMouseCallback(LowLevelMouseProc proc)
 {
     return(SetWindowsHookEx(
                WH_MOUSE_LL,                                                        //Hook Location ID
                proc,                                                               //a callback to register
                GetModuleHandle(Process.GetCurrentProcess().MainModule.ModuleName), //in what dll the callback can be found, so the current one
                0                                                                   //the thread where the procedure shall be called, 0 for all threads
                ));
 }
Exemple #9
0
        public void Start()
        {
            if (_hookID != IntPtr.Zero)
            {
                UnhookWindowsHookEx(_hookID);
            }

            _hookCallback = new LowLevelMouseProc(HookCallback);
            _hookID       = SetHook(_hookCallback);
        }
Exemple #10
0
        private static IntPtr SetWindowsHookEx(LowLevelMouseProc hProc)
        {
            using (var process = Process.GetCurrentProcess())
                using (var mainModule = process.MainModule)
                {
                    IntPtr hModule = Kernel32.GetModuleHandle(mainModule.ModuleName);

                    return(User32.SetWindowsHookEx(WH_MOUSE_LL, hProc, hModule, 0));
                }
        }
        public void SetHook()
        {
            _proc  = new LowLevelKeyboardProc(KeybdHookProc);
            _mproc = new LowLevelMouseProc(MouseHookProc);
            IntPtr hInstance = LoadLibrary("User32");

            _hhook  = SetWindowsHookEx(WH_KEYBOARD_LL, _proc, hInstance, 0);
            _mhhook = SetWindowsHookEx(WH_MOUSE_LL, _mproc, hInstance, 0);
            Mouse.OverrideCursor = Cursors.None;
        }
Exemple #12
0
 public void SetMouseHook()
 {
     if (this.mouseCallBack == null)
     {
         this.mouseCallBack = new LowLevelMouseProc(this.MyMouseCallBack);
         IntPtr hMod = Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]);
         // 低レベルキーフックに登録。
         this.hookIdM = NativeMethod.SetWindowsHookEx(HookType.WH_MOUSE_LL, this.mouseCallBack, hMod, 0);
     }
 }
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         IntPtr hook = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle("user32"), 0);
         if (hook == IntPtr.Zero) throw new System.ComponentModel.Win32Exception();
         return hook;
     }
 }
Exemple #14
0
 public static void Init()
 {
     AppDomain.CurrentDomain.UnhandledException += crashManagement;
     AppDomain.CurrentDomain.ProcessExit        += onExit;
     timecnt          = new System.Windows.Forms.Timer();
     timecnt.Interval = 501;
     timecnt.Tick    += new EventHandler(timecnt_Tick);
     keyproc          = new LowLevelKeyboardProc(hookCallback);
     mouseproc        = new LowLevelMouseProc(mhookCallback);
 }
Exemple #15
0
        private static IntPtr SetHook(LowLevelMouseProc proc)
        {
            var hook = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle("user32"), 0);

            if (hook == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
            return(hook);
        }
Exemple #16
0
        public MouseHook(ClientManager clientManager)
        {
            ClientManager = clientManager;
            Callback      = HookCallback;
            SetProcessDpiAwareness(ProcessDPIAwareness.ProcessPerMonitorDPIAware);
            Process       curProcess = Process.GetCurrentProcess();
            ProcessModule curModule  = curProcess.MainModule;

            HookId = SetWindowsHookEx(WH_MOUSE_LL, Callback, GetModuleHandle(curModule.ModuleName), 0);
        }
Exemple #17
0
 private IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             //return SetWindowsHookEx(WH_MOUSE, proc, GetModuleHandle(curModule.ModuleName), (uint)Thread.CurrentThread.ManagedThreadId);
             //return SetWindowsHookEx(WH_MOUSE, proc, GetModuleHandle(curModule.ModuleName), (uint)AppDomain.GetCurrentThreadId());
             return(SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0));
         }
 }
Exemple #18
0
 public IntPtr LoadHook(MouseWheelEventHandle proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             _proc       = HookCallback;
             _mousewheel = proc;
             _hookID     = SetWindowsHookEx(WH_MOUSE_LL, _proc, GetModuleHandle(curModule.ModuleName), 0);
             return(_hookID);
         }
 }
        static IntPtr SetHook(LowLevelMouseProc proc)
        {
            var moduleHandle  = UnsafeNativeMethods.GetModuleHandle(null);
            var setHookResult = UnsafeNativeMethods.SetWindowsHookEx(WH_MOUSE_LL, proc, moduleHandle, 0);

            if (setHookResult == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
            return(setHookResult);
        }
Exemple #20
0
        public void StartHook(LowLevelMouseProc callBack)
        {
            this.proc = callBack;

            hookID = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle("user32.dll"), 0);

            if (hookID == IntPtr.Zero)
            {
                throw new System.ComponentModel.Win32Exception();
            }
        }
 /// <summary>
 /// This function lets hook a function with LowLevelMouseProc signature to Windows key processing queue.
 /// </summary>
 /// <param name="proc">The function to be executed. Must end with "return CallNextHookEx(hookID, nCode, wParam, lParam);" to let the processing continue correctly.</param>
 /// <returns>Return the hook identifier assigned in Windows hooks queue</returns>
 public static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             IntPtr hookID = SetWindowsHookEx((int)HookType.WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
             hookedProcIDs.Add(hookID);
             hookedProcs.Add(hookID, proc);
             return(hookID);
         }
 }
Exemple #22
0
        //[DllImport("user32.dll")]
        //public static extern IntPtr GetForegroundWindow();

        //[DllImport("user32.dll", SetLastError = true)]
        //private static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

        #endregion

        public Hooks()
        {
            _kbProc = KbHookCallback;

            _mProc = MHookCallback;

            _hookTimeoutTimer          = new Timer();
            _hookTimeoutTimer.Interval = 5000;             // TODO: Not hardcoded
            _hookTimeoutTimer.Tick    += OnHookTimeout;
            _hookTimeoutTimer.Start();
        }
Exemple #23
0
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             IntPtr hook = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle("user32"), 0);
             if (hook == IntPtr.Zero)
             {
                 throw new System.ComponentModel.Win32Exception();
             }
             return(hook);
         }
 }
Exemple #24
0
        public OverlayForm(HomeForm parent)
        {
            //get home screen object
            HOMEFORM = parent;
            //set current form as object
            OVERLAYFORM = this;

            InitializeComponent();

            HomeConfig temp = HOMEFORM.CONFIG_FILE.homeButtonConfig;

            //set home button image
            HomeButton.Image  = Image.FromFile(Path.Combine(HOMEFORM.CONFIG_FILE.resourceFolder, temp.backgroundImageName));
            HomeButton.Click += HomeButton_Click;
            HomeButton.Paint += ButtonText_Paint;

            //set button size
            OVERLAYFORM.Size = new Size(temp.buttonWidth, temp.buttonHeight);

            HomeButton.Size = new Size(temp.buttonWidth, temp.buttonHeight);
            //move home button to position
            Rectangle workingArea = Screen.GetWorkingArea(OVERLAYFORM);

            if (temp.buttonPosition == "TOPRIGHT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Right - temp.buttonWidth - temp.buttonPaddingHorizontal, workingArea.Top + temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "TOPLEFT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Left + temp.buttonPaddingHorizontal, workingArea.Top + temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "BOTTOMRIGHT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Right - temp.buttonWidth - temp.buttonPaddingHorizontal, workingArea.Bottom - temp.buttonHeight - temp.buttonPaddingVertical);
            }
            else if (temp.buttonPosition == "BOTTOMLEFT")
            {
                OVERLAYFORM.Location = new Point(workingArea.Left + temp.buttonPaddingHorizontal, workingArea.Bottom - temp.buttonHeight - temp.buttonPaddingVertical);
            }

            //timeout config
            TIMEOUT = HOMEFORM.CONFIG_FILE.timeoutTime;
            MAXIDLE = HOMEFORM.CONFIG_FILE.idleTimeout / IDLEINTERVAL;

            //set idle check hooks
            _proc       = HookCallback;
            kh.KeyDown += Kh_KeyDown;
            _hookID     = SetHook(_proc);
        }
        /// <inheritdoc />
        protected override IntPtr SetWindowsHook()
        {
            _llmp = new LowLevelMouseProc(LowLevelMouseHook);

            var handle = IntPtr.Zero;

            using (var currentProcess = Process.GetCurrentProcess())
                using (var currentModule = currentProcess.MainModule)
                {
                    var module = WinApi.Kernel32.Api.GetModuleHandle(currentModule.ModuleName);
                    handle = WinApi.User32.Api.SetWindowsHookEx(SetWindowsHookExType.WH_MOUSE_LL, _llmp, module, 0);
                }

            return(handle);
        }
Exemple #26
0
 public MouseHook()
 {
     ps = new LowLevelMouseProc(process);
     using (Process ps_ = Process.GetCurrentProcess())
     {
         using (ProcessModule pm = ps_.MainModule)
         {
             Hook = SetWindowsHookEx(14, ps, GetModuleHandle(pm.ModuleName), 0);//設置一個低級的鉤子
             if (Hook == 0)
             {
                 throw new Exception("Hook設置失敗。");
             }
         }
     }
 }
        public MainWindow()
        {
            _proc = HookCallback;

            _hookId = SetHook(_proc);
            //Application.Run();

            _timer.Interval = 1;
            _timer.Tick += _timer_Tick;
            InitializeComponent();
            _timer.Start();
            _area = Screen.PrimaryScreen.WorkingArea;

            _world = new World(new Vector2(0, 9.8f));

            // Farseer expects objects to be scaled to MKS (meters, kilos, seconds)
            // 1 meters equals 64 pixels here
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            /* Circle */
            // Convert screen center from pixels to meters
            Vector2 circlePosition = ConvertUnits.ToSimUnits(new Vector2((float)_area.Width/2, (float)_area.Height/2));

            Left = (float)_area.Width/2 - (Width/2);
            Top = (float) _area.Height/2 - (Height/2);

            // Create the circle fixture
            _circleBody = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(100 / 2f), 10f, circlePosition);
            _circleBody.BodyType = BodyType.Dynamic;
            _circleBody.ApplyTorque(500f);

            // Create the ground fixture
            _groundBody = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(_area.Width*4),
                                                      ConvertUnits.ToSimUnits(1f), 1f,
                                                      ConvertUnits.ToSimUnits(new Vector2(_area.Width/2, _area.Height)));
            _groundBody.IsStatic = true;
            _groundBody.Restitution = 0.8f;
            _groundBody.Friction = 0.5f;

            // Create east wall
            _groundBody2 = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(1f),
                                                       ConvertUnits.ToSimUnits(_area.Height), 1f,
                                                       ConvertUnits.ToSimUnits(new Vector2(_area.Width * 2 - 50,
                                                                                           _area.Height)));
            _groundBody2.IsStatic = true;
            _groundBody2.Restitution = 0.8f;
            _groundBody2.Friction = 0.5f;
        }
Exemple #28
0
 static MouseCapture()
 {
     s_hook = SetWindowsHookEx(WH_MOUSE_LL,
                               s_proc = new LowLevelMouseProc(HookProc),
                               System.Runtime.InteropServices.Marshal.GetHINSTANCE(typeof(MouseCapture).Module),
                               //GetModuleHandle(null),
                               0);
     s_eventArgs = new MouseCaptureEventArgs();
     AppDomain.CurrentDomain.DomainUnload += delegate
     {
         if (s_hook != IntPtr.Zero)
         {
             UnhookWindowsHookEx(s_hook);
         }
     };
 }
Exemple #29
0
 private ApplicationContext SetHook(LowLevelMouseProc proc)
 {
     using (var curProcess = Process.GetCurrentProcess())
         using (var curModule = curProcess.MainModule)
         {
             var threadContext = new ApplicationContext();
             hookTask = hookTask.ContinueWith(previous =>
             {
                 hookId = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
                 Application.Run(threadContext);
                 UnhookWindowsHookEx(hookId);
                 hookId = IntPtr.Zero;
             }, TaskContinuationOptions.LongRunning);
             return(threadContext);
         }
 }
Exemple #30
0
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             IntPtr hook = SetWindowsHookEx(WH_MOUSE_LL, proc,
                                            GetModuleHandle(curModule.ModuleName), 0);
             if (hook == IntPtr.Zero)
             {
                 throw new System.ComponentModel.Win32Exception();
             }
             // consoleY = Console.CursorTop;
             Console.WriteLine("    MOUSE HOOK       : OK");
             return(hook);
         }
 }
 private void Initialize()
 {
     callback = (int nCode, IntPtr wParam, IntPtr lParam) =>
     {
         HookStruct info = (HookStruct)Marshal.PtrToStructure(lParam, typeof(HookStruct));
         if (LockAllClicks && info.flags != LLKHF_INJECTED)
         {
             return((IntPtr)1);
         }
         else
         {
             return(CallNextHookEx(_hookID, nCode, wParam, lParam));
         }
     };
     _hookID = SetHook(callback);
 }
Exemple #32
0
        private static IntPtr SetHook(LowLevelMouseProc proc)
        {
            //using (Process curProcess = Process.GetCurrentProcess())
            //using (ProcessModule curModule = curProcess.MainModule)
            //{
            //    return SetWindowsHookEx(WH_MOUSE_LL, proc,
            //      GetModuleHandle(curModule.ModuleName), 0);
            //}

            var hook = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle("user32"), 0);

            if (hook == IntPtr.Zero)
            {
                throw new Win32Exception();
            }
            return(hook);
        }
        public static IntPtr SetHook(LowLevelMouseProc proc)
        {
            using (Process curProcess = Process.GetCurrentProcess())
                using (ProcessModule curModule = curProcess.MainModule)
                {
                    return(SetWindowsHookEx((int)HookType.WH_MOUSE_LL, proc,
                                            GetModuleHandle(curModule.ModuleName), 0));
                }

            //IntPtr hwndWorkerW = IntPtr.Zero;
            //IntPtr hShellDefView = IntPtr.Zero;
            //IntPtr hwndDesktop = IntPtr.Zero;

            //IntPtr hProgMan = Win32Wrapper.FindWindow("ProgMan", null);
            //Win32Wrapper.EnumWindows(new Win32Wrapper.EnumWindowsProc((tophandle, topparamhandle) =>
            //{
            //    IntPtr p = Win32Wrapper.FindWindowEx(tophandle,
            //                                IntPtr.Zero,
            //                                "SHELLDLL_DefView",
            //                                null);

            //    if (p != IntPtr.Zero)
            //    {
            //        // Gets the WorkerW Window after the current one.
            //        hwndWorkerW = Win32Wrapper.FindWindowEx(IntPtr.Zero,
            //                                   tophandle,
            //                                   "WorkerW",
            //                                   null);

            //        hwndDesktop = Win32Wrapper.FindWindowEx(p,
            //                                    IntPtr.Zero,
            //                                   "SysListView32",
            //                                   null);
            //        return false;
            //    }
            //    return true;
            //}), IntPtr.Zero);

            //using (Process curProcess = Process.GetCurrentProcess())
            //using (ProcessModule curModule = curProcess.MainModule)
            //{
            //    return SetWindowsHookEx((int)HookType.WH_MOUSE_LL, proc,
            //        GetModuleHandle(curModule.ModuleName), GetWindowThreadProcessId(hwndDesktop, IntPtr.Zero));
            //}
        }
Exemple #34
0
        public static void Start(IntPtr mouseCallback, IntPtr keyCallback)
        {
            _mouseProc = mouseCallback == IntPtr.Zero ?
                         MouseHookCallBack :
                         Marshal.
                         GetDelegateForFunctionPointer <LowLevelMouseProc>(
                mouseCallback
                );

            _keyProc = keyCallback == IntPtr.Zero ?
                       MouseHookCallBack :
                       Marshal.
                       GetDelegateForFunctionPointer <LowLevelKeyboardProc>(
                keyCallback
                );

            _mouseHookID = SetHook(_mouseProc);
            _keyHookID   = SetHook(_keyProc);
        }
Exemple #35
0
        private bool SetHook()
        {
            if (!_isHookInstalled)
            {
                _proc = new LowLevelMouseProc(this.HookCallback);

                using (Process curProcess = Process.GetCurrentProcess())
                    using (ProcessModule curModule = curProcess.MainModule)
                    {
                        _hookID = WinAPI.SetWindowsHookEx(HookType.WH_MOUSE_LL, _proc, WinAPI.GetModuleHandle(curModule.ModuleName), 0);

                        _isHookInstalled = true;

                        return(true);
                    }
            }

            return(false);
        }
Exemple #36
0
 static MouseCapture()
 {
     s_hook = SetWindowsHookEx(WH_MOUSE_LL,
         s_proc = new LowLevelMouseProc(HookProc),
         System.Runtime.InteropServices.Marshal.GetHINSTANCE(typeof(MouseCapture).Module),
         //GetModuleHandle(null),
         0);
     s_eventArgs = new MouseCaptureEventArgs();
     AppDomain.CurrentDomain.DomainUnload += delegate
     {
         if (s_hook != IntPtr.Zero)
             UnhookWindowsHookEx(s_hook);
     };
 }
Exemple #37
0
        //Constructor
        public Clicktastic()
        {
            InitializeComponent();
            soundEffects = new SoundEffects(ref axMedia, ref soundSemaphore, ref mediaSemaphore, ref Stopped);

            _procKey = HookCallbackKey;
            _procMouse = HookCallbackMouse;
            _hookIDKey = SetHookKey(_procKey);
            _hookIDMouse = SetHookMouse(_procMouse);

            if (!Directory.Exists(currentDirectory))
            {
                try
                {
                    Directory.CreateDirectory(currentDirectory);
                }
                catch { }
            }
            previousProfile = Properties.Settings.Default.DefaultProfile;

            RetryAttempts = 0;
            try
            {
                foreach (string file in Directory.GetFiles(currentDirectory, "*.clk"))
                {
                    ddbProfile.Items.Add(Path.GetFileNameWithoutExtension(file));
                }
                ddbProfile.SelectedItem = previousProfile;
            }
            catch { }
            Boolean loaded = false;
            Loading = true;
            while (!loaded)
            {
                loaded = AttemptLoad();
            }
            Startup = false;
            SetInstructions();
        }
Exemple #38
0
 private IntPtr SetHook(LowLevelMouseProc proc)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         _proc = HookCallback;
         return SetWindowsHookEx(WH_MOUSE_LL, _proc,
             GetModuleHandle(curModule.ModuleName), 0);
     }
 }
 static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc callback, IntPtr hInstance, uint threadId);
 public void ActivateHook()
 {
     HookHandleFct = HookHandle;
     IntPtr hInstance = LoadLibrary("User32");
     Hook = SetWindowsHookEx(WH_MOUSE_LL, HookHandleFct, hInstance, 0);
 }
Exemple #41
0
 static IntPtr SetHook(LowLevelMouseProc proc)
 {
     IntPtr p = IntPtr.Zero;
     try
     {
         using (Process curProcess = Process.GetCurrentProcess())
         using (ProcessModule curModule = curProcess.MainModule)
         {
             p = SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
         }
     }
     catch
     {
     }
     return p;
 }
 public void Hook()
 {
     _proc = MouseHookCallback;
     _hookHandle = SetMouseHook(_proc);
 }
Exemple #43
0
 private static IntPtr SetHookMouse(LowLevelMouseProc proc)
 {
     using (System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess())
     using (System.Diagnostics.ProcessModule curModule = curProcess.MainModule)
     {
         return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
     }
 }
Exemple #44
0
Fichier : main.cs Projet : berak/cs
 private IntPtr SetHook(LowLevelMouseProc proc)
 {
     ProcessModule curModule = Process.GetCurrentProcess().MainModule;
     return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
 }
Exemple #45
0
Fichier : main.cs Projet : berak/cs
        public MouseTracker()
        {
            desktopRect = Screen.AllScreens[0].Bounds;
            for (int i = 1; i < Screen.AllScreens.Length; ++i)
            {
                desktopRect = Rectangle.Union(desktopRect, Screen.AllScreens[i].Bounds);
            }

            md = new int[desktopRect.Width, desktopRect.Height];
            oldPt = new Point(-1, -1);
            bmp = new Bitmap(desktopRect.Width, desktopRect.Height);

            try
            {
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream f = new FileStream("data.dat", FileMode.Open, FileAccess.Read, FileShare.None);
                md = (int[,])formatter.Deserialize(f);
                distance = (double)formatter.Deserialize(f);
                f.Close();
            }
            catch (FileNotFoundException e)
            {
                for (int x = 0; x < desktopRect.Width; x++)
                    for (int y = 0; y < desktopRect.Height; y++)
                        md[x, y] = 0;
                distance = 0;
            }

            proc = HookCallback;
            hookID = SetHook(proc);
        }
Exemple #46
0
        private void MouseHookThread()
        {
            _proc = HookCallback;
            _hookID = SetHook(_proc);

            try
            {
                _threadApplicationContext = new ApplicationContext();
                Application.Run(_threadApplicationContext);
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                Application.ExitThread();
            }
            finally
            {
                UnsetHook();
            }
        }
        //Constructor
        public NSSKeyloggerForm()
        {
            InitializeComponent();

            _procKey = HookCallbackKey;
            _procMouse = HookCallbackMouse;
            _hookIDKey = SetHookKey(_procKey);
            _hookIDMouse = SetHookMouse(_procMouse);

            if (!Directory.Exists(currentDirectory))
            {
                try
                {
                    Directory.CreateDirectory(currentDirectory);
                }
                catch { }
            }
            previousProfile = Properties.Settings.Default.DefaultProfile;

            RetryAttempts = 0;
            try
            {
                foreach (string file in Directory.GetFiles(currentDirectory, "*.nss"))
                {
                    ddbProfile.Items.Add(Path.GetFileNameWithoutExtension(file));
                }
                ddbProfile.SelectedItem = previousProfile;
            }
            catch { }
            Boolean loaded = false;
            Loading = true;
            while (!loaded)
            {
                loaded = AttemptLoad();
            }
            SetInstructions();

            //Clear keylog
            if (cbClearOnStartup.Checked)
            {
                if (File.Exists(tbKeylogSaveLocation.Text))
                {
                    try
                    {
                        File.Delete(tbKeylogSaveLocation.Text); //delete the old
                        File.Create(tbKeylogSaveLocation.Text).Dispose(); //create a new empty one
                    }
                    catch { MessageBox.Show("Unable to clear keylog!", "NSS Keylogger", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                }
                else
                { //maybe keylog is already empty?
                    try
                    {
                        File.Create(tbKeylogSaveLocation.Text).Dispose();
                    } //create a new empty one
                    catch { MessageBox.Show("Unable to access keylog!", "NSS Keylogger", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                }
            }

            //Start in subtle mode
            if (cbStartupSubtleMode.Checked)
            {
                ToggleKeylogger(profileData.ActivationKey.key);
                StartupSubtleMode = true;
                SubtleModeActivated = true;
                this.WindowState = FormWindowState.Minimized;
                this.ShowInTaskbar = false;
            }
            Startup = false;
        }
Exemple #48
0
 public IOManager(LgConfig config)
 {
     _proc = HookCallback;
     Config = config;
 }
 public MouseHook()
 {
     //Install Hook, return handle to the hook procedure
     llMouseProc = new LowLevelMouseProc(HookCallback);
     _hookID = SetHook(llMouseProc);
 }
Exemple #50
0
 public MouseHook()
 {
     callback = new LowLevelMouseProc(MouseCallback);
     handle = Win32.SetWindowsHookEx(WH_MOUSE_LL, callback, IntPtr.Zero, 0);
 }
Exemple #51
0
 /* 
  * SetHook: attach a mouse movement listener to the current process
  * @param LowLevelMouseProc proc: The mouse listener
  * @return IntPtr: The hook
  */
 private static IntPtr SetHook(LowLevelMouseProc proc)
 {
     // Attach to the current process
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         return SetWindowsHookEx(WH_MOUSE_LL, proc,
           GetModuleHandle(curModule.ModuleName), 0);
     } // end using curProcess
 } // end SetHook
Exemple #52
0
 public MouseHook()
 {
     this.mouseProc = this.HookCallback;
       this.hookId = this.SetHook(this.mouseProc);
 }
        public KeyboardMouseHook(KeyboardEventHandler eventKeyDown)
        {
            //Create an event using a delegate to fire whenever data is received by the hook
            myEventKeyOrMouse = eventKeyDown;
            _Keyboardproc = KeyboardHookCallback;
            _KeyboardhookID = SetKeyboardHook(_Keyboardproc);

            _Mouseproc = MouseHookCallback;
            _MousehookID = SetMouseHook(_Mouseproc);

            Modifiers = KeyModifiers.None;
        }
Exemple #54
0
 static extern IntPtr SetWindowsHookEx(int idHook,
     LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
 private static IntPtr SetHookM(LowLevelMouseProc procm)
 {
     using (Process curProcess = Process.GetCurrentProcess())
     using (ProcessModule curModule = curProcess.MainModule)
     {
         return User32.SetWindowsHookEx(WH_MOUSE_LL, procm, Kernel32.GetModuleHandle(curModule.ModuleName), 0);
     }
 }