Exemple #1
0
 /// <summary>
 /// Releases a held key
 /// </summary>
 /// <param name="key">The key to be released</param>
 public static void SendKeyUp(VirtualKeyCodes.VirtualKeys key)
 {
     WinApi.INPUT input = new WinApi.INPUT();
     input.input = new WinApi.COMBINEDINPUT()
     {
         keyboardInput = CreateKeyUp(key)
     };
     input.type = 1;
     WinApi.SendInput(1, new WinApi.INPUT[] { input }, Marshal.SizeOf(typeof(WinApi.INPUT)));
 }
Exemple #2
0
        public static void KeyUp(Keys key)
        {
            Thread.Sleep(Delay);
            WinApi.INPUT[] inputs = new WinApi.INPUT[1];
            inputs[0].type       = (int)WinApi.INPUT_TYPE.INPUT_KEYBOARD;
            inputs[0].ki.wVk     = (byte)key;
            inputs[0].ki.wScan   = GetScanCode(key);
            inputs[0].ki.dwFlags = WinApi.KEYEVENTF_KEYUP;
            uint intReturn = WinApi.SendInput(1, inputs, System.Runtime.InteropServices.Marshal.SizeOf(inputs[0]));

            if (intReturn != 1)
            {
                throw new Exception("Could not send key: " + key);
            }
        }
        private void MenuViewForm_Load(object sender, EventArgs e)
        {
            BackColor = Color.FromArgb(byte.MaxValue, Main.Colors.Base.R, Main.Colors.Base.G, Main.Colors.Base.B);
            if (Main.ScreenDpi > 96)
                Font = SystemFonts.CaptionFont;
            Icon = Resources.PortableApps_blue;
            MaximumSize = Screen.FromHandle(Handle).WorkingArea.Size;
            Lang.SetControlLang(this);
            for (var i = 0; i < appMenu.Items.Count; i++)
                appMenu.Items[i].Text = Lang.GetText(appMenu.Items[i].Name);
            if (Main.SetFont(this))
                layoutPanel.Size = new Size(Width - 2, Height - 2);
            Main.SetFont(appMenu);

            layoutPanel.BackgroundImage = Main.BackgroundImage;
            layoutPanel.BackgroundImageLayout = Main.BackgroundImageLayout;
            layoutPanel.BackColor = Main.Colors.Base;
            layoutPanel.SetControlStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer);
            ControlEx.DrawSizeGrip(layoutPanel, Main.Colors.Base,
                (o, args) =>
                {
                    Point point;
                    switch (TaskBar.GetLocation(Handle))
                    {
                        case TaskBar.Location.Right:
                            point = new Point(1, Height - 1);
                            break;
                        case TaskBar.Location.Bottom:
                            point = new Point(Width - 1, 1);
                            break;
                        default:
                            point = new Point(Width - 1, Height - 1);
                            break;
                    }
                    WinApi.UnsafeNativeMethods.ClientToScreen(Handle, ref point);
                    WinApi.UnsafeNativeMethods.SetCursorPos((uint)point.X, (uint)point.Y);
                    var inputMouseDown = new WinApi.INPUT();
                    inputMouseDown.Data.Mouse.Flags = 0x0002;
                    inputMouseDown.Type = 0;
                    var inputMouseUp = new WinApi.INPUT();
                    inputMouseUp.Data.Mouse.Flags = 0x0004;
                    inputMouseUp.Type = 0;
                    WinApi.INPUT[] inputs =
                    {
                        inputMouseUp,
                        inputMouseDown
                    };
                    WinApi.UnsafeNativeMethods.SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(WinApi.INPUT)));
                },
                (o, args) =>
                {
                    var p = o as PictureBox;
                    if (p == null)
                        return;
                    switch (TaskBar.GetLocation(Handle))
                    {
                        case TaskBar.Location.Right:
                        case TaskBar.Location.Bottom:
                            p.Cursor = Cursors.SizeNESW;
                            break;
                        default:
                            p.Cursor = Cursors.SizeNWSE;
                            break;
                    }
                });

            _hideHScrollBar = Ini.ReadBoolean("Settings", "Window.HideHScrollBar");
            MenuViewForm_Resize(this, EventArgs.Empty);
            if (Main.ScreenDpi > 96)
                appsListViewPanel.Font = SystemFonts.SmallCaptionFont;
            appsListViewPanel.BackColor = Main.Colors.Control;
            appsListViewPanel.ForeColor = Main.Colors.ControlText;
            appsListView.BackColor = appsListViewPanel.BackColor;
            appsListView.ForeColor = appsListViewPanel.ForeColor;
            appsListView.SetControlStyle(ControlStyles.OptimizedDoubleBuffer);
            WinApi.UnsafeNativeMethods.SendMessage(appsListView.Handle, 0x103e, IntPtr.Zero, Cursors.Arrow.Handle);

            searchBox.BackColor = Main.Colors.Control;
            searchBox.ForeColor = Main.Colors.ControlText;
            searchBox.DrawSearchSymbol(Main.Colors.ControlText);
            SearchBox_Leave(searchBox, EventArgs.Empty);

            title.ForeColor = Main.BackgroundImage.GetAverageColor().InvertRgb().ToGrayScale();
            logoBox.Image = Resources.PortableApps_Logo_gray.Redraw(logoBox.Height, logoBox.Height);
            appsCount.ForeColor = title.ForeColor;

            aboutBtn.BackgroundImage = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.Help, Main.SystemResourcePath)?.ToBitmap();
            aboutBtn.BackgroundImage = aboutBtn.BackgroundImage.SwitchGrayScale($"{aboutBtn.Name}BackgroundImage");

            profileBtn.BackgroundImage = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.UserDir, true, Main.SystemResourcePath)?.ToBitmap();
            downloadBtn.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.Network, Main.SystemResourcePath)?.ToBitmap();
            settingsBtn.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.SystemControl, Main.SystemResourcePath)?.ToBitmap();
            foreach (var btn in new[] { downloadBtn, settingsBtn })
            {
                btn.BackColor = Main.Colors.Button;
                btn.ForeColor = Main.Colors.ButtonText;
                btn.FlatAppearance.MouseDownBackColor = Main.Colors.Button;
                btn.FlatAppearance.MouseOverBackColor = Main.Colors.ButtonHover;
            }

            appMenu.CloseOnMouseLeave(32);
            appMenu.EnableAnimation();
            appMenu.SetFixedSingle(Main.Colors.Base);
            appMenuItem2.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.Uac, Main.SystemResourcePath)?.ToBitmap();
            appMenuItem3.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.Directory, Main.SystemResourcePath)?.ToBitmap();
            appMenuItem5.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.Pin, Main.SystemResourcePath)?.ToBitmap();
            appMenuItem7.Image = ResourcesEx.GetSystemIcon(ResourcesEx.ImageresIconIndex.RecycleBinEmpty, Main.SystemResourcePath)?.ToBitmap();

            var docDir = PathEx.Combine(PathEx.LocalDir, "Documents");
            if (Directory.Exists(docDir) && Data.DirIsLink(docDir) && !Data.MatchAttributes(docDir, FileAttributes.Hidden))
                Data.SetAttributes(docDir, FileAttributes.Hidden);

            _windowOpacity = Ini.ReadDouble("Settings", "Window.Opacity", 95);
            if (_windowOpacity.IsBetween(20d, 100d))
                _windowOpacity /= 100d;
            else
                _windowOpacity = .95d;

            _windowFadeInDuration = Ini.ReadInteger("Settings", "Window.FadeInDuration", 1);
            if (_windowFadeInDuration < 1)
                _windowFadeInDuration = 1;
            var opacity = (int)(_windowOpacity * 100d);
            if (_windowFadeInDuration > opacity)
                _windowFadeInDuration = opacity;

            var windowWidth = Ini.ReadInteger("Settings", "Window.Size.Width", MinimumSize.Width);
            if (windowWidth > MinimumSize.Width && windowWidth < MaximumSize.Width)
                Width = windowWidth;
            if (windowWidth > MaximumSize.Width)
                Width = MaximumSize.Width;

            var windowHeight = Ini.ReadInteger("Settings", "Window.Size.Height", MinimumSize.Height);
            if (windowHeight > MinimumSize.Height && windowHeight < MaximumSize.Height)
                Height = windowHeight;
            if (windowHeight > MaximumSize.Height)
                Height = MaximumSize.Height;

            MenuViewForm_Update();
        }