Exemple #1
0
        private HotkeysManager()
        {
            var keyboardHook = new LowLevelKeyboardHook(true);
            var mouseHook    = new LowLevelMouseHook(true);

            _hotkeys = new Dictionary <string, HotkeyCommand>();

            foreach (var settings in Properties.Hotkeys.Default.Properties.Cast <SettingsProperty>())
            {
                if (!(Properties.Hotkeys.Default[settings.Name] is VirtualKeyCode keyCode))
                {
                    continue;
                }

                _hotkeys.Add(settings.Name, new HotkeyCommand
                {
                    KeyCode = keyCode
                });

                Logger.Get.Info($"Added hotkey {keyCode} for action {settings.Name}");
            }

            Properties.Hotkeys.Default.PropertyChanged += OnSettingsPropertyChanged;

            keyboardHook.OnKeyboardEvent += OnKeyboardEvent;
            keyboardHook.InstallHook();

            mouseHook.OnMouseEvent += MouseHook_OnMouseEvent;
            mouseHook.InstallHook();

            Messenger.Default.Register <GameActiveStatusChanged>(this, msg =>
            {
                mouseHook.CaptureMouseMove = msg.IsInForeground;
            });
        }
        public Desktop()
        {
            windowToBody      = new Dictionary <Window, Body>();
            contactJoints     = new Dictionary <int, FixedHingeJoint>();
            engine            = new PhysicsEngine();
            engine.BroadPhase = new SweepAndPruneDetector();
            engine.Solver     = new SequentialImpulsesSolver();
            timer             = new PhysicsTimer(PhysicsTimerCallback, 0.01);
            timer.IsRunning   = true;

            injectorClass = new DWMInjectorClass();
            if (!injectorClass.IsInjected)
            {
                injectorClass.Inject();
            }
            injectorClass.GetDWMExObject(out dwm);
            Debug.Assert(dwm != null, "DWM is NULL");

            windowManager = new WindowManager();
            windowManager.WindowCreated   += windowManager_WindowCreated;
            windowManager.WindowDestroyed += windowManager_WindowDestroyed;
            windowManager.Register(MessageEvents.Handle);

            ThreadPool.QueueUserWorkItem(delegate
            {
                hook = new LowLevelMouseHook(MouseHook);
                hook.StartHook();
                Application.Run();
            });
        }
        private void Overlay_Loaded(object sender, RoutedEventArgs e)
        {
            // Start topmost updater
            _winHook = new WindowHook();
            _winHook.BrawlhallaOpened += (_, __) => MessageBox.Show("bh opened");
            _winHook.WindowFocused    += (_, __) => this.Topmost = true;
            _winHook.LostWindowFocus  += (_, __) => this.Topmost = false;

            // Add ping items
            var config = ConfigManager.GetPingConfig();

            foreach (var server in config.ServersEnabled)
            {
                var item = new PingItem(server.Name, Utilities.GetIPToPingFromName(server.Name), server.XPos, server.YPos);

                (this.Content as Canvas).Children.Add(item);
                item.MoveTo(item.XPos, item.YPos);
            }

            // Create low level mouse hook
            LowLevelMouseHook.Hook();

            // Handle moving of ping items
            LowLevelMouseHook.MouseDown  += Overlay_MouseDown;
            LowLevelMouseHook.MouseMoved += Overlay_MouseMoved;
            LowLevelMouseHook.MouseUp    += Overlay_MouseUp;
        }
Exemple #4
0
        public override void Start()
        {
            foreach (RawDevice device in RawDevice.GetRawDevices())
            {
                if (device.RawType == RawType.Mouse)
                {
                    deviceList.Add(device.Handle, new CursorData());
                }
            }

            Thread t = new Thread((ThreadStart) delegate
            {
                RawDevice.RegisterRawDevices(0x01, 0x02,
                                             InputMode.BackgroundMode | InputMode.SuppressMessages);
                RawDevice.RawInput += RawDevice_RawInput;
                lowLevelMouseHook   = new LowLevelMouseHook(MouseHookCallback);
                System.Windows.Forms.Application.Run();
            });

            t.IsBackground = true;
            t.SetApartmentState(ApartmentState.STA);
            t.Start();

            timer          = new Timer(10);
            timer.Elapsed += timer_Elapsed;
            timer.Start();

            Mouse.OverrideCursor = Cursors.None;

            isRunning = true;
        }
Exemple #5
0
        public void ShowDragVisual(Control control)
        {
            UpdatePosition();
            User32.ShowWindow(this.Handle, 8);
            User32.SetWindowPos(
                this.Handle, (IntPtr)(-1),
                0, 0, 0, 0,
                0x0010 | 0x0002 | 0x001);

            try
            {
                _hook = new LowLevelMouseHook();
                _hook.Activate(0);
            }
            catch (Win32Exception)
            {
                if (_hook != null)
                {
                    _hook.Dispose();
                    _hook = null;
                }
            }

            if (_hook == null)
            {
                _timer.Enabled = true;
                if (control != null)
                {
                    control.GiveFeedback += OnControlGiveFeedback;
                }
            }
            else
            {
                _hook.MouseMove += (s, e) =>
                {
                    if (InvokeRequired)
                    {
                        BeginInvoke(new Action <Point>(UpdatePosition), e.Location);
                    }
                    else
                    {
                        UpdatePosition(e.Location);
                    }
                };
                _hook.MouseWheel += (s, e) =>
                {
                    if (e.Delta == 0)
                    {
                        return;
                    }
                    var h = User32.WindowFromPoint(new POINT(e.X, e.Y));
                    if (h == IntPtr.Zero)
                    {
                        return;
                    }
                    User32.SendMessage(h, WM.MOUSEWHEEL, (IntPtr)(e.Delta << 16), (IntPtr)((e.Y << 16) | e.X));
                };
            }
        }
Exemple #6
0
 public LLRecorder()
 {
     llkbHook                      = new LowLevelKeyboardHook();
     llMouseHook                   = new LowLevelMouseHook();
     llkbHook.KeyIntercepted      += new LowLevelKeyboardHook.KeyCallback(llkbHook_KeyIntercepted);
     llMouseHook.MouseIntercepted += new LowLevelMouseHook.MouseCallback(llMouseHook_MouseIntercepted);
     entries = new List <IRecordEntry>();
 }
Exemple #7
0
        public void DisposeWhenNotActivatedTest()
        {
            var hook = new LowLevelMouseHook((evnt, data) => { return(LowLevelMouseHook.Result.Transfer); });

            Assert.IsFalse(hook.IsActivated);
            hook.Dispose();
            Assert.IsFalse(hook.IsActivated);
        }
        public WindowFinder()
        {
            this.InitializeComponent();

            this.crosshairsCursor = ConvertToCursor(this.WindowInfoControl, cursorHotSpot);

            this.lowLevelMouseHook = new LowLevelMouseHook();
            this.lowLevelMouseHook.LowLevelMouseMove += this.LowLevelMouseMove;
        }
Exemple #9
0
        void InputWorker()
        {
            RawDevice.RegisterRawDevices(0x01, 0x02, InputMode.BackgroundMode);
            RawDevice.RegisterRawDevices(HID_USAGE_PAGE_DIGITIZER, HID_USAGE_DIGITIZER_PEN, InputMode.BackgroundMode);
            RawDevice.RawInput += RawDevice_RawInput;

            hook = new LowLevelMouseHook(OnMouseAction);

            Application.Run();
        }
Exemple #10
0
        public void ActivatedTest()
        {
            var hook = new LowLevelMouseHook((evnt, data) => { return(LowLevelMouseHook.Result.Transfer); });

            Assert.IsFalse(hook.IsActivated);
            hook.SetHook();
            Assert.IsTrue(hook.IsActivated);
            hook.Unhook();
            Assert.IsFalse(hook.IsActivated);
        }
Exemple #11
0
 public MacroRecorder()
 {
     macroEntries             = new List <MacroRecordEntry>();
     watch                    = new Stopwatch();
     kbHook                   = new LowLevelKeyboardHook();
     msHook                   = new LowLevelMouseHook();
     kbHook.Callback         += new Hook.HookCallback(HookCallback);
     msHook.Callback         += new Hook.HookCallback(HookCallback);
     kbHook.KeyIntercepted   += new LowLevelKeyboardHook.KeyCallback(kbHook_KeyIntercepted);
     msHook.MouseIntercepted += new LowLevelMouseHook.MouseCallback(msHook_MouseIntercepted);
 }
Exemple #12
0
        public VersionInfo()
        {
            this.Focusable        = false;
            this.ShowActivated    = false;
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;

            InitializeComponent();

            mouseHook = new LowLevelMouseHook();
            mouseHook.MouseIntercepted += new LowLevelMouseHook.MouseCallback(mouseHook_MouseIntercepted);
        }
Exemple #13
0
    public async Task DefaultTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelMouseHook().WithEventLogging();

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
        public InputProvider()
        {
            RunPipeServer();

            AppConfig.ConfigChanged += AppConfig_ConfigChanged;
            LowLevelMouseHook        = new LowLevelMouseHook();

            if (AppConfig.DrawingButton != MouseActions.None)
            {
                LowLevelMouseHook.StartHook();
            }
        }
Exemple #15
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_hook != null)
         {
             _hook.Dispose();
             _hook = null;
         }
         _timer.Dispose();
     }
     base.Dispose(disposing);
 }
Exemple #16
0
        public InputProvider()
        {
            _messageWindow = new MessageWindow();
            _messageWindow.PointsIntercepted += MessageWindow_PointsIntercepted;

            AppConfig.ConfigChanged += AppConfig_ConfigChanged;
            LowLevelMouseHook        = new LowLevelMouseHook();
            if (AppConfig.DrawingButton != MouseActions.None)
            {
                Task.Delay(1000).ContinueWith((t) =>
                {
                    LowLevelMouseHook.StartHook();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
        }
Exemple #17
0
        public void UnhookThrowsInvalidOperationExceptionTestTest()
        {
            var hook = new LowLevelMouseHook((evnt, data) => { return(LowLevelMouseHook.Result.Transfer); });

            hook.SetHook();
            hook.Unhook();
            try
            {
                hook.Unhook();
            }
            catch (InvalidOperationException)
            {
                return;
            }
            Assert.Fail();
        }
        public static void Main(string[] args)
        {
            LowLevelKeyboardHook kbdHook   = new LowLevelKeyboardHook();
            LowLevelMouseHook    mouseHook = new LowLevelMouseHook();

            kbdHook.OnKeyboardEvent += KbdHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent  += MouseHook_OnMouseEvent;

            kbdHook.InstallHook();
            mouseHook.InstallHook();

            while (true)
            {
                Thread.Sleep(1);
            }
        }
Exemple #19
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _windowGetter         = new BackgroundWorker();
            _windowGetter.DoWork += new DoWorkEventHandler(_windowGetter_DoWork);
            _windowGetter.RunWorkerAsync();

            _windowHiglight       = new WindowHighlight();
            _windowHiglight.Owner = this;


            _updateUI               = new UpdateDel(UpdateUI);
            _mousehook              = new LowLevelMouseHook("low level mouse hook");
            _mousehook.OnMouseMove += new EventHandler <System.Windows.Forms.MouseEventArgs>(_mousehook_OnMouseMove);
            _mousehook.OnMouseDown += new EventHandler <System.Windows.Forms.MouseEventArgs>(_mousehook_OnMouseDown);
            _mousehook.Install();
        }
Exemple #20
0
    public async Task AddKeyboardKeysTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelMouseHook
              {
                  AddKeyboardKeys        = true,
                  IsLeftRightGranularity = true,
                  IsCapsLock             = true,
                  IsExtendedMode         = true,
              }.WithEventLogging();

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
Exemple #21
0
    public async Task HandlingTest()
    {
        using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
        var cancellationToken = cancellationTokenSource.Token;

        using var hook = new LowLevelMouseHook
              {
                  Handling = true,
              }.WithEventLogging();
        hook.Move += (_, args) => args.IsHandled = true;
        hook.Down += (_, args) => args.IsHandled = true;
        hook.Up   += (_, args) => args.IsHandled = true;

        hook.Start();

        await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
    }
Exemple #22
0
        public void Hook()
        {
            ProcessModule objCurrentModule = Process.GetCurrentProcess().MainModule;

            if (objKeyboardProcess == null)
            {
                objKeyboardProcess = new LowLevelKeyboardProc(captureKey);
            }
            ptrKeyBoardHook = IntPtr.Zero;
            ptrKeyBoardHook = SetWindowsHookEx(13, objKeyboardProcess, GetModuleHandle(objCurrentModule.ModuleName), 0);

            if (objMouseProcess == null)
            {
                objMouseProcess = new LowLevelMouseHook(MouseKeyCode);
            }
            ptrMouseHook = IntPtr.Zero;
            ptrMouseHook = SetWindowsHookEx(14, objMouseProcess, GetModuleHandle(objCurrentModule.ModuleName), 0);
        }
Exemple #23
0
        static void Main(string[] args)
        {
            TestFilter();

            return;

            // creates a new instance to capture inputs
            // also provides IsPressed, WasPressed and GetState methods
            var inputManager = new InputManager();

            // you may not need those when you use InputManager
            var keyboardHook = new LowLevelKeyboardHook();
            var mouseHook    = new LowLevelMouseHook();

            // subscribe to the events offered by InputManager
            inputManager.OnKeyboardEvent += InputManager_OnKeyboardEvent;
            inputManager.OnMouseEvent    += InputManager_OnMouseEvent;

            // same events as above (in case you only need a specific hook and less functionality)
            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            // we need to initialize our classes before they fire events and are completely usable
            inputManager.Initialize();
            keyboardHook.InstallHook();
            mouseHook.InstallHook();

            // registers an event (callback) which gets fired whenever the key changes it's state
            // be sure to use this method after the InputManager is initialized
            inputManager.RegisterEvent(VirtualKeyCode.Lbutton, InputManager_KeyStateChanged);

            Console.WriteLine("Waiting for up arrow key to exit!");

            // This method will block the current thread until the up arrow key changes it's state to Down
            // There is no performance penalty (spinning loop waiting for this)
            inputManager.WaitForEvent(VirtualKeyCode.Up, KeyState.Down);

            // be sure to dispose instances you dont use anymore
            // not doing so may block windows input and let inputs appear delayed or lagging
            // these classes try dispose itself when an unhandled exception occurs or the process exits
            mouseHook.Dispose();
            keyboardHook.Dispose();
            inputManager.Dispose();
        }
Exemple #24
0
        public void LowLevelMouseHookProcTest()
        {
            var sender = new SingleInputSender();
            var list   = new List <LowLevelMouseHook.Event>();
            var hook   = new LowLevelMouseHook((evnt, data) => {
                if (data.fromCreviceApp)
                {
                    list.Add(evnt);
                    return(LowLevelMouseHook.Result.Cancel);
                }
                return(LowLevelMouseHook.Result.Transfer);
            });

            Assert.AreEqual(list.Count, 0);
            hook.SetHook();
            sender.RightClick();
            hook.Unhook();
            Assert.AreEqual(list.Count, 2);
        }
Exemple #25
0
        //The Core off applications is here
        #region SetUp/SetDown/CheckUps/Updates
        private static void SetUp()
        {
            Console.CursorVisible = false;
            Console.Title         = "Senac Clicker GameJam";

            GetData();
            SetUpVars();
            // Disable the Console Edit mode, in way to never lock the main thread during execution due to selections on the window.
            DisableQuickEdit();
            // Initialize Hookers who deal with all the inputs after now.
            KeyboardHook = new LowLevelKeyboardHook();
            MouseHook    = new LowLevelMouseHook();
            // Defines actions to events.
            KeyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            MouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;
            // Attach the hookers into main thread.
            KeyboardHook.InstallHook();
            MouseHook.InstallHook();
        }
Exemple #26
0
 private void timer1_Tick(object sender, EventArgs e)
 {
     timer1.Enabled = false;
     if (llhook)
     {
         kbd   = new LowLevelKeyboardHook();
         mouse = new LowLevelMouseHook();
         kbd.MessageIntercepted   += new LowLevelMessageCallback(ll_MessageIntercepted);
         mouse.MessageIntercepted += new LowLevelMessageCallback(ll_MessageIntercepted);
         kbd.StartHook();
         mouse.StartHook();
     }
     else
     {
         rec              = new JournalRecordHook();
         rec.RecordEvent += new EventHandler <JournalRecordEventArgs>(rec_RecordEvent);
         rec.StartHook();
     }
 }
Exemple #27
0
        public InputProvider()
        {
            _messageWindow = new MessageWindow();
            _messageWindow.PointsIntercepted += MessageWindow_PointsIntercepted;

            AppConfig.ConfigChanged += AppConfig_ConfigChanged;
            LowLevelMouseHook        = new LowLevelMouseHook();
            if (AppConfig.DrawingButton != MouseActions.None)
            {
                Task.Delay(1000).ContinueWith((t) =>
                {
                    LowLevelMouseHook.StartHook();
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }


            SystemEvents.SessionSwitch    += new SessionSwitchEventHandler(OnSessionSwitch);
            SystemEvents.PowerModeChanged += new PowerModeChangedEventHandler(OnPowerModeChanged);

            _deviceStateServer = new CustomNamedPipeServer(Common.Constants.Daemon + "DeviceState", IpcCommands.SynDeviceState,
                                                           () => HidDevice.EnumerateDevices());
        }
        private void Initialize(bool captureMouseMove, bool clearInjectedFlag)
        {
            // initialize vars
            lockObject = new object();

            mapKeyState = new Dictionary <VirtualKeyCode, KeyState>();

            foreach (var pair in KeyCodeConverter.EnumerateVirtualKeyCodes())
            {
                mapKeyState.Add(pair.Key, KeyState.None);
            }

            singleKeyCallback = new Dictionary <VirtualKeyCode, List <KeyStateChangedCallback> >();

            // initialize hooks
            keyboardHook = new LowLevelKeyboardHook(clearInjectedFlag);
            mouseHook    = new LowLevelMouseHook(captureMouseMove, clearInjectedFlag);

            keyboardHook.OnKeyboardEvent += KeyboardHook_OnKeyboardEvent;
            mouseHook.OnMouseEvent       += MouseHook_OnMouseEvent;

            keyboardHook.InstallHook();
            mouseHook.InstallHook();
        }
Exemple #29
0
 public MouseGestureForm(AppGlobal Global)
 {
     this.mouseHook = new LowLevelMouseHook(MouseProc);
     this.Global    = Global;
 }
 private void Overlay_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     LowLevelMouseHook.UnHook();
 }