Example #1
0
        private void MouseButtonOnMouseButtonInputChanged(object sender, MouseInputArgs e)
        {
            if (_lastKnownSc2 == null)
            {
                return;
            }

            if (_lastKnownSc2.HasExited)
            {
                return;
            }

            if (NativeMethods.GetForegroundWindow() != _lastKnownSc2.MainWindowHandle)
            {
                return;
            }

            var mapping = _settings.Mappings.Find((x) => x.Source == e.Key);

            if (mapping == null)
            {
                return;
            }

            SimulateToSc2(mapping.Target);
            e.Suppress = mapping.Hook;
        }
Example #2
0
        public static bool HookMouse()
        {
            if (MouseHookRegistered)
            {
                return(true);
            }

            bool result = false;

            _mouse = (int code, IntPtr wParam, IntPtr lParam) =>
            {
                NativeMethods.WMessages msg = (NativeMethods.WMessages)wParam;

                // If the code is less than 0, Windows want it to be processed without touching..
                // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644985(v=vs.85).aspx
                if (code < 0 || msg != NativeMethods.WMessages.XButtonDown)
                {
                    return(NativeMethods.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
                }

                MSLLHOOKSTRUCT data = Marshal.PtrToStructure <MSLLHOOKSTRUCT>(lParam);

                int xButton = data.mouseData >> 16;
                var button  = (XMouseButtons)xButton;
                var asKeys  = button == XMouseButtons.XButton1 ? Keys.XButton1 : Keys.XButton2;

                MouseInputArgs args = new MouseInputArgs(msg, lParam, asKeys);

                OnMouseButtonInputChanged(null, args);

                if (args.Suppress)
                {
                    return((IntPtr)1);
                }

                // Console.WriteLine($"{data.mouseData.ToString("X4")}");

                return(NativeMethods.CallNextHookEx(IntPtr.Zero, code, wParam, lParam));
            };

            IntPtr hook    = NativeMethods.SetWindowsHookEx(NativeMethods.HookType.WH_MOUSE_LL, _mouse, IntPtr.Zero, 0);
            var    myerror = Marshal.GetLastWin32Error();

            if (hook == IntPtr.Zero)
            {
                // Write to file?
                // myerror
            }
            else
            {
                MouseHook           = hook;
                result              = true;
                MouseHookRegistered = true;
            }

            return(result);
        }
Example #3
0
 private static void OnMouseButtonInputChanged(object o, MouseInputArgs e)
 {
     MouseButtonInputChanged?.Invoke(o, e);
 }