protected override void Awake()
    {
        base.Awake();

        windowDP = GetComponentInChildren <DPDesktopOverlay>();
    }
Exemplo n.º 2
0
        private IEnumerator C_JoinDiscord()
        {
            //Clipboard.SetText("https://discord.gg/adVEQmY");

            Process.Start("https://discord.gg/adVEQmY");

            yield break;

            UwcWindow        discordWindow = null;
            DPDesktopOverlay discordDP     = null;
            DPApp            discordDPApp  = null;

            //See if discord is opened already
            foreach (DPDesktopOverlay desktopDP in DPDesktopOverlay.overlays)
            {
                if (desktopDP.isTargetingWindow && desktopDP.window.title.EndsWith("- Discord"))
                {
                    discordDP     = desktopDP;
                    discordWindow = desktopDP.window;

                    break;
                }
            }

            //If the overlay isn't already opened, we try to spawn a new one
            if (discordWindow == null)
            {
                //See if discord is opened
                foreach (UwcWindow window in UwcManager.windows.Values)
                {
                    if (window.title.EndsWith("- Discord"))
                    {
                        discordWindow = window;

                        discordDP = OverlayManager.I.NewDPWindowOverlay(discordWindow);

                        break;
                    }
                }
            }

//TODO: Launch discord
            //if (discordWindow == null || discordDP == null) {

            Process.Start("https://discord.gg/adVEQmY");

            yield break;
            //}


            //Find the DPApp
            foreach (DPApp app in TheBarManager.openApps.Values)
            {
                if (app.dpMain == discordDP)
                {
                    discordDPApp = app;
                    break;
                }
            }


            if (discordWindow.isIconic)
            {
                WinNative.ShowWindow(discordWindow.handle, ShowWindowCommands.Restore);
            }

            TheBarManager.I.LaunchAppToMainSnap(discordDPApp.appKey);

            WinNative.SetForegroundWindow(discordWindow.handle);

            yield return(new WaitForSeconds(0.2f));

            yield return(new WaitForSeconds(0.2f));

            //const int WM_KEYDOWN = 0x100;
            //const int WM_KEYUP = 0x101;

            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LCONTROL, 0);
            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LSHIFT, 0);
            //WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_N, 0);

            InputSimulator inputSimulator = new InputSimulator();

            //inputSimulator.Keyboard.KeyDown(VirtualKeyCode.CONTROL);
            inputSimulator.Keyboard.ModifiedKeyStroke(new[] { VirtualKeyCode.LCONTROL, VirtualKeyCode.LSHIFT }, new[] { VirtualKeyCode.VK_N });

            yield return(new WaitForSeconds(0.2f));

            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);
            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.TAB);

            inputSimulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);

            yield return(new WaitForSeconds(0.2f));

            inputSimulator.Keyboard.TextEntry("https://discord.gg/adVEQmY");



            /*//Tab 3 times to the join server button:
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_TAB, 0);
             *
             * yield return null;
             *
             * //Enter
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_RETURN, 0);
             *
             * yield return new WaitForSeconds(0.2f);
             *
             * //Paste in the join link
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_LCONTROL, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_V, 0);
             * yield return null;
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYUP, (int)KeysEx.VK_V, 0);
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYUP, (int)KeysEx.VK_LCONTROL, 0);
             *
             * yield return null;
             *
             * //Enter to join:
             * WinNative.PostMessageSafe(discordWindow.handle, WM_KEYDOWN, (int)KeysEx.VK_RETURN, 0);*/
        }