private void SimulateBorderScrolling(POINT origin)
        {
            POINT point = origin;

            ScreenToClient(LatestRa3.MainWindowHandle, ref point);
            Size size = WindowInvocation.GetClientSize(LatestRa3);


            if (!size.IsPointInArea(origin.X, origin.Y))
            {
                return;
            }

            // I wanted to make it cool but it somewhat looks not so cool. :(
            void Check(bool condition, Keys key, ref bool keyNeedsUp)
            {
                uint scanCode        = MapVirtualKeyEx((uint)key, MAPVK_VK_TO_VSC, IntPtr.Zero);
                uint goodScanCode    = scanCode << 16; // scancode is from 16-23, byte
                uint extendedMessage = goodScanCode
                                       | 1             // Key repeating
                                       | 1 << 24;      // is extended key = true

                if (condition)
                {
                    Pinvokes.PostMessage(LatestRa3.MainWindowHandle, (int)WM.KeyDown, 0, extendedMessage);
                    keyNeedsUp = true;
                }
                else
                {
                    if (keyNeedsUp)
                    {
                        Pinvokes.PostMessage(LatestRa3.MainWindowHandle, (int)WM.KeyUp, 0, extendedMessage);
                        keyNeedsUp = false;
                    }
                }

                /*
                 * Inputs.SendMessage(LatestRa3.MainWindowHandle, (int)WM.KeyDown, 0x25, 0x14b0001);
                 * Inputs.SendMessage(LatestRa3.MainWindowHandle, (int)WM.KeyUp, 0x25, 0xc14b0001);
                 * //Messaging.InvokeKeyPress(LatestRa3.MainWindowHandle, (uint) Keys.Left);
                 * Console.WriteLine("Invoked keypress");*/
            }

            // Left
            Check(point.X <= Constants.Ra3InnerScrollBorderSize, Keys.Left, ref needsKeyUp1);

            // Right
            Check(size.Width - point.X <= Constants.Ra3InnerScrollBorderSize, Keys.Right, ref needsKeyUp2);

            // Up
            Check(point.Y <= Constants.Ra3InnerScrollBorderSize, Keys.Up, ref needsKeyUp3);

            // Down
            Check(size.Height - point.Y <= Constants.Ra3InnerScrollBorderSize, Keys.Down, ref needsKeyUp4);
        }
示例#2
0
        private void ForegroundWatcher_ForegroundChanged(object sender, ForegroundArgs e)
        {
            if (e.Process.ProcessName != "ra3_1.12.game")
            {
                return;
            }

            Log("RA3 Window found");
            latestRa3 = e.Process;

            if (settings.RemoveBorder)
            {
                if (!WindowInvocation.DropBorder(e.Process))
                {
                    Log("Remove Window Border failed.");
                }
                if (!WindowInvocation.ResizeWindow(e.Process))
                {
                    Log("Resize Window failed.");
                }
            }

            if (settings.LockCursor)
            {
                WindowInvocation.ClipCursor(e.Process);
            }

            if (settings.InvokeAltUp)
            {
                Task.Delay(100).ContinueWith(_ =>
                {
                    Messaging.SimulateAltKeyPress(e.Process.MainWindowHandle);
                    // Messaging.InvokeSysKeyPress(e.Process.MainWindowHandle, (uint) Keys.Menu);
                    // Messaging.InvokeSysKeyPress(e.Process.MainWindowHandle, (int)Keys.Menu); // ALT key
                });
            }

            if (settings.RefreshPathToRa3)
            {
                try
                {
                    // Dirty?
                    string manualPath = Path.Combine(
                        Path.GetDirectoryName(Path.GetDirectoryName(e.Process.MainModule.FileName))
                        , "RA3.exe"
                        );
                    txtRa3Path.Text = manualPath;
                }catch (Exception err)
                {
                    err = err;
                }
            }
        }
        private void SystemWatcherSystemChanged(object sender, ProcessArgs e)
        {
            if (e.Process.ProcessName != Constants.Ra3ProcessName)
            {
                return;
            }

            if (LatestRa3 == null || LatestRa3.HasExited)
            {
                LatestRa3 = e.Process;
            }

            if (settings.LaunchRa3Windowed)
            {
                _mouseWatcher.WatchCursor(settings.SleepTime);
            }

            if (settings.RemoveBorder)
            {
                WindowInvocation.DropBorder(e.Process);
                WindowInvocation.ResizeWindow(e.Process);
                Logger.Info("OK.. drop border and resize");
            }

            if (settings.LockCursor)
            {
                bool success = WindowInvocation.LockToProcess(e.Process);
                Logger.Info($"OK.. lock cursor to ra3 window. success: {success}");
            }

            if (settings.InvokeAltUp)
            {
                Task.Delay(100).ContinueWith(_ =>
                {
                    Inputs.SimulateAltKeyPress(e.Process.MainWindowHandle);
                    // Messaging.InvokeSysKeyPress(e.Process.MainWindowHandle, (uint) Keys.Menu);
                    // Messaging.InvokeSysKeyPress(e.Process.MainWindowHandle, (int)Keys.Menu); // ALT key
                    Logger.Info("OK.. invoke alt keypress after ra3 has gained focus");
                });
            }
        }
        private void SwapWinKeyState(bool disableKey)
        {
            if (disableKey)
            {
                _keyboardWatcher.DisableKey(() =>
                {
                    Process foregroundProcess = WindowInvocation.GetForegroundProcess();

                    if (foregroundProcess == null)
                    {
                        return(false);
                    }

                    return(foregroundProcess.ProcessName == Constants.Ra3ProcessName);
                }, Keys.LWin, Keys.RWin);
            }
            else
            {
                _keyboardWatcher.EnableKey(Keys.LWin, Keys.RWin);
            }
        }