Example #1
0
        /// <summary>
        /// Redraws the TextBox when necessary.
        /// </summary>
        private static Hotkey ValidateHotkey(Keys key, Keys modifiers)
        {
            if (key == Keys.LWin || key == Keys.RWin)
            {
                key = Keys.None;
            }

            Hotkey validatedHotkey = new Hotkey(key, Hotkey.ConvertToWin32Modifiers(modifiers));

            // No hotkey set
            if (key == Keys.None ||
                (modifiers == Keys.None && !NoModifierIsNeededFor(key)))
            {
                validatedHotkey = new Hotkey(Keys.None, SCICT.Utility.Windows.Modifiers.None);
            }

            else if (modifiers.Has(Keys.Shift) &&
                     !modifiers.Has(Keys.Control) &&
                     !modifiers.Has(Keys.Alt) &&
                     needNonShiftModifier.Contains((int)key))
            {
                validatedHotkey = new Hotkey(Keys.None, SCICT.Utility.Windows.Modifiers.None);
            }
            // I have no idea why this is needed, but it is. Without this code, pressing only Ctrl
            // will show up as "Control + ControlKey", etc.
            else if (key == Keys.Menu /* Alt */ || key == Keys.ShiftKey || key == Keys.ControlKey)
            {
                validatedHotkey = new Hotkey(Keys.None, SCICT.Utility.Windows.Modifiers.None);
            }

            ManagedWinapi.KeyboardKey kKey = new ManagedWinapi.KeyboardKey(key);
            ThisAddIn.DebugWriteLine(kKey.KeyName);

            return(validatedHotkey);
        }
Example #2
0
        private static void SendPasteKey(Hotkey hotkey)
        {
            var shiftKey = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.ShiftKey);
            var altKey   = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.Alt);
            var ctrlKey  = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.ControlKey);
            var vKey     = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.V);

            // Before injecting a paste command, first make sure that no modifiers are already
            // being pressed (which will throw off the Ctrl+v).
            // Since key state is notoriously unreliable, set a max sleep so that we don't get stuck
            var maxSleep = 250;

            // minimum sleep time
            System.Threading.Thread.Sleep(150);

            //System.Diagnostics.Debug.WriteLine("shift: " + shiftKey.State + " alt: " + altKey.State + " ctrl: " + ctrlKey.State);

            while (maxSleep > 0 && (shiftKey.State != 0 || altKey.State != 0 || ctrlKey.State != 0))
            {
                System.Threading.Thread.Sleep(maxSleep -= 50);
            }

            //System.Diagnostics.Debug.WriteLine("maxSleep: " + maxSleep);

            // press keys in sequence. Don't use PressAndRelease since that seems to be too fast
            // for most applications and the sequence gets lost.
            ctrlKey.Press();
            vKey.Press();
            System.Threading.Thread.Sleep(25);
            vKey.Release();
            System.Threading.Thread.Sleep(25);
            ctrlKey.Release();
        }
Example #3
0
        protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
        {
            window.Hide();
            Clipboard.SetText(path);
            var a = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.LControlKey);
            var b = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.V);

            a.Press(); b.Press(); a.Release(); b.Release();
            Top();
        }
Example #4
0
        private string GetDescription(HotKeySettings Settings)
        {
            if (Settings == null)
            {
                return("Send a hot key combination to application");
            }

            // Create string to store key combination and final output description
            string strKeyCombo        = "";
            string strFormattedOutput = "Send the hot key ({0}) to application";

            // Build output string
            if (Settings.Windows)
            {
                strKeyCombo = "Win + ";
            }

            if (Settings.Control)
            {
                strKeyCombo += "Ctrl + ";
            }

            if (Settings.Alt)
            {
                strKeyCombo += "Alt + ";
            }

            if (Settings.Shift)
            {
                strKeyCombo += "Shift + ";
            }

            strKeyCombo += new ManagedWinapi.KeyboardKey(Settings.KeyCode).KeyName;             // Settings.KeyCode.ToString();

            // Return final formatted string
            return(String.Format(strFormattedOutput, strKeyCombo));
        }
Example #5
0
 protected override void OnMouseRightButtonDown(MouseButtonEventArgs e)
 {
     window.Hide();
     Clipboard.SetText(path);
     var a = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.LControlKey);
     var b = new ManagedWinapi.KeyboardKey(System.Windows.Forms.Keys.V);
     a.Press(); b.Press(); a.Release(); b.Release();
     Top();
 }
Example #6
0
        private void SendShortcutKeys(HotKeySettings Settings)
        {
            if (Settings == null)
                return;

            // Create keyboard keys to represent hot key combinations
            ManagedWinapi.KeyboardKey winKey = new ManagedWinapi.KeyboardKey(Keys.LWin);
            ManagedWinapi.KeyboardKey controlKey = new ManagedWinapi.KeyboardKey(Keys.LControlKey);
            ManagedWinapi.KeyboardKey altKey = new ManagedWinapi.KeyboardKey(Keys.LMenu);
            ManagedWinapi.KeyboardKey shiftKey = new ManagedWinapi.KeyboardKey(Keys.LShiftKey);
            ManagedWinapi.KeyboardKey modifierKey = new ManagedWinapi.KeyboardKey(Settings.KeyCode);

            // Deceide which keys to press
            // Windows
            if (Settings.Windows)
                winKey.Press();

            // Control
            if (Settings.Control)
                controlKey.Press();

            // Alt
            if (Settings.Alt)
                altKey.Press();

            // Shift
            if (Settings.Shift)
                shiftKey.Press();

            // Modifier
            modifierKey.PressAndRelease();

            // Release Shift
            if (Settings.Shift)
                shiftKey.Release();

            // Release Alt
            if (Settings.Alt)
                altKey.Release();

            // Release Control
            if (Settings.Control)
                controlKey.Release();

            // Release Windows
            if (Settings.Windows)
                winKey.Release();
        }
Example #7
0
        private string GetDescription(HotKeySettings Settings)
        {
            if (Settings == null)
                return "Send a hot key combination to application";

            // Create string to store key combination and final output description
            string strKeyCombo = "";
            string strFormattedOutput = "Send the hot key ({0}) to application";

            // Build output string
            if (Settings.Windows)
                strKeyCombo = "Win + ";

            if (Settings.Control)
                strKeyCombo += "Ctrl + ";

            if (Settings.Alt)
                strKeyCombo += "Alt + ";

            if (Settings.Shift)
                strKeyCombo += "Shift + ";

            strKeyCombo += new ManagedWinapi.KeyboardKey(Settings.KeyCode).KeyName; // Settings.KeyCode.ToString();

            // Return final formatted string
            return String.Format(strFormattedOutput, strKeyCombo);
        }
Example #8
0
        private void SendShortcutKeys(HotKeySettings Settings)
        {
            if (Settings == null)
            {
                return;
            }

            // Create keyboard keys to represent hot key combinations
            ManagedWinapi.KeyboardKey winKey      = new ManagedWinapi.KeyboardKey(Keys.LWin);
            ManagedWinapi.KeyboardKey controlKey  = new ManagedWinapi.KeyboardKey(Keys.LControlKey);
            ManagedWinapi.KeyboardKey altKey      = new ManagedWinapi.KeyboardKey(Keys.LMenu);
            ManagedWinapi.KeyboardKey shiftKey    = new ManagedWinapi.KeyboardKey(Keys.LShiftKey);
            ManagedWinapi.KeyboardKey modifierKey = new ManagedWinapi.KeyboardKey(Settings.KeyCode);

            // Deceide which keys to press
            // Windows
            if (Settings.Windows)
            {
                winKey.Press();
            }

            // Control
            if (Settings.Control)
            {
                controlKey.Press();
            }

            // Alt
            if (Settings.Alt)
            {
                altKey.Press();
            }

            // Shift
            if (Settings.Shift)
            {
                shiftKey.Press();
            }

            // Modifier
            modifierKey.PressAndRelease();

            // Release Shift
            if (Settings.Shift)
            {
                shiftKey.Release();
            }

            // Release Alt
            if (Settings.Alt)
            {
                altKey.Release();
            }

            // Release Control
            if (Settings.Control)
            {
                controlKey.Release();
            }

            // Release Windows
            if (Settings.Windows)
            {
                winKey.Release();
            }
        }