Beispiel #1
0
 public void Up()
 {
     GenerateStrings();
     if (_keyString.Length > 0)
     {
         KeyboardEmulator.KeyUp(_keyUpString);
     }
 }
Beispiel #2
0
        protected override void OnSourceInitialized(EventArgs e)
        {
            base.OnSourceInitialized(e);

            try
            {
                // Load window placement details for previous application session from application settings
                // Note - if window was closed on a monitor that is now disconnected from the computer,
                //        SetWindowPlacement will place the window onto a visible monitor.

                if (PreferencesFile.IsSettingAvailable("ControlCenter", "WindowLocation"))
                {
                    WINDOWPLACEMENT wp = new WINDOWPLACEMENT();
                    wp.normalPosition = PreferencesFile.LoadSetting("ControlCenter", "WindowLocation",
                                                                    new RECT(0, 0, (int)Width, (int)Height));
                    wp.length  = Marshal.SizeOf(typeof(WINDOWPLACEMENT));
                    wp.flags   = 0;
                    wp.showCmd = (wp.showCmd == NativeMethods.SW_SHOWMINIMIZED
                        ? NativeMethods.SW_SHOWNORMAL
                        : wp.showCmd);
                    IntPtr hwnd = new WindowInteropHelper(this).Handle;
                    NativeMethods.SetWindowPlacement(hwnd, ref wp);
                }

                if (!Enum.TryParse(Preferences.HotKeyModifiers, out ModifierKeys mods))
                {
                    HotKeyDescription = "None";
                    return;
                }
                if (!Enum.TryParse(Preferences.HotKey, out Keys hotKey))
                {
                    HotKeyDescription = "None";
                    return;
                }
                if (hotKey != Keys.None)
                {
                    _hotkey = new HotKey(mods, hotKey, this);
                    _hotkey.HotKeyPressed += new Action <HotKey>(HotKeyPressed);
                    HotKeyDescription      = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) +
                                             _hotkey.Key.ToString();
                }
                else
                {
                    HotKeyDescription = "None";
                }
            }
            catch (System.Exception ex)
            {
                ConfigManager.LogManager.LogError("exception thrown during hotkey initialization", ex);
                RemoveHotkey();
            }
        }
Beispiel #3
0
 public void Press()
 {
     GenerateStrings();
     if (_keyString.Length > 0)
     {
         if (_comboKeyString.Length > 0)
         {
             KeyboardEmulator.KeyPress(_comboKeyString + " " + _keyString);
         }
         else
         {
             KeyboardEmulator.KeyPress(_keyString);
         }
     }
 }
        /// <summary>
        /// Toggles toolmode eg. tool=>hand | hand=>tool
        /// </summary>
        internal void toggleToolMode()
        {
            // Written, 08.10.2020

            if (isPlayerHandEmpty())
            {
                VirtualKeyShort?wVk = null;

                if (isInToolMode)
                {
                    wVk = VirtualKeyShort.KEY_1;
                }
                else if (isPlayerHandEmpty())
                {
                    wVk = VirtualKeyShort.KEY_2;
                }
                StartCoroutine(KeyboardEmulator.simulateKeyPressCoroutine((VirtualKeyShort)wVk));
            }
        }
Beispiel #5
0
        public void DecryptMetadata(bool copyToClipboard, bool type)
        {
            var selectedFile = RequestPasswordFile();
            KeyedPasswordFile passFile;

            try
            {
                passFile = passwordManager.DecryptPassword(selectedFile, ConfigManager.Config.PasswordStore.FirstLineOnly);
            }
            catch (GpgError e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (GpgException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed. " + e.Message);
                return;
            }
            catch (ConfigurationException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (Exception e)
            {
                notificationService.ShowErrorWindow($"Password decryption failed: An error occurred: {e.GetType().Name}: {e.Message}");
                return;
            }

            if (copyToClipboard)
            {
                clipboard.Place(passFile.Metadata, TimeSpan.FromSeconds(ConfigManager.Config.Interface.ClipboardTimeout));
                if (ConfigManager.Config.Notifications.Types.PasswordCopied)
                {
                    notificationService.Raise($"The key has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.Interface.ClipboardTimeout:0.##} seconds.", Severity.Info);
                }
            }
            if (type)
            {
                KeyboardEmulator.EnterText(passFile.Metadata, ConfigManager.Config.Output.DeadKeys);
            }
        }
Beispiel #6
0
        private void SetHotkey_Click(object sender, RoutedEventArgs e)
        {
            HotKeyDetector detector = new HotKeyDetector();

            detector.Owner = this;
            detector.ShowDialog();

            if (_hotkey != null)
            {
                _hotkey.UnregisterHotKey();
                _hotkey.Dispose();
            }

            _hotkey = new HotKey(detector.Modifiers, detector.Key, _helper.Handle);
            _hotkey.HotKeyPressed += HotKeyPressed;

            Preferences.HotKeyModifiers = detector.Modifiers.ToString();
            Preferences.HotKey          = detector.Key.ToString();
            HotKeyDescription           = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString();
        }
Beispiel #7
0
        private void SetHotkey_Click(object sender, RoutedEventArgs e)
        {
            HotKeyDetector detector = new HotKeyDetector();

            detector.Owner = this;
            detector.ShowDialog();

            if (_hotkey != null)
            {
                _hotkey.UnregisterHotKey();
                _hotkey.Dispose();
            }

            _hotkey = new HotKey(detector.Modifiers, detector.Key, _helper.Handle);
            _hotkey.HotKeyPressed += new Action <HotKey>(HotKeyPressed);

            ConfigManager.SettingsManager.SaveSetting("ControlCenter", "HotKeyModifiers", detector.Modifiers.ToString());
            ConfigManager.SettingsManager.SaveSetting("ControlCenter", "HotKey", detector.Key.ToString());

            HotKeyDescription = KeyboardEmulator.ModifierKeysToString(_hotkey.KeyModifier) + _hotkey.Key.ToString();
        }
Beispiel #8
0
        void ComponentDispatcher_ThreadPreprocessMessage(ref MSG msg, ref bool handled)
        {
            if (msg.message == NativeMethods.WM_KEYDOWN)
            {
                Modifiers = Modifiers | ModifierForVK((Keys)msg.wParam);
            }
            if (msg.message == NativeMethods.WM_KEYUP)
            {
                Keys         upKey = (Keys)msg.wParam;
                ModifierKeys mods  = ModifierForVK(upKey);
                if (mods != ModifierKeys.None)
                {
                    Modifiers = Modifiers & ~ModifierForVK(upKey);
                }
                else if (upKey != Keys.None)
                {
                    Key = upKey;
                    DispatcherTimer minizeTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 250), DispatcherPriority.Normal, TimedClose, Dispatcher);
                    minizeTimer.Start();
                }
            }

            HotKeyDescription = KeyboardEmulator.ModifierKeysToString(Modifiers) + Key.ToString();
        }
 void KeyUp_ExecuteAction(object action, HeliosActionEventArgs e)
 {
     KeyboardEmulator.KeyUp(e.Value.StringValue);
 }
Beispiel #10
0
        public void GetKey(bool copyToClipboard, bool type, string key)
        {
            var selectedFile = RequestPasswordFile();

            if (selectedFile == null)
            {
                return;
            }

            KeyedPasswordFile passFile;

            try
            {
                passFile = passwordManager.DecryptPassword(selectedFile, ConfigManager.Config.PasswordStore.FirstLineOnly);
            }
            catch (GpgError e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (GpgException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed. " + e.Message);
                return;
            }
            catch (ConfigurationException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (Exception e)
            {
                notificationService.ShowErrorWindow($"Password decryption failed: An error occurred: {e.GetType().Name}: {e.Message}");
                return;
            }

            if (string.IsNullOrWhiteSpace(key))
            {
                var keys      = passFile.Keys.Select(k => k.Key).Distinct();
                var selection = ShowPasswordMenu(keys);
                if (selection == null)
                {
                    return;
                }
                key = selection;
            }

            var values = passFile.Keys.Where(k => k.Key == key).ToList();

            if (values.Count == 0)
            {
                return;
            }

            string chosenValue;

            if (values.Count > 1)
            {
                chosenValue = ShowPasswordMenu(values.Select(v => v.Value));
                if (chosenValue == null)
                {
                    return;
                }
            }
            else
            {
                chosenValue = values[0].Value;
            }


            if (copyToClipboard)
            {
                clipboard.Place(chosenValue, TimeSpan.FromSeconds(ConfigManager.Config.Interface.ClipboardTimeout));
                if (ConfigManager.Config.Notifications.Types.PasswordCopied)
                {
                    notificationService.Raise($"The key has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.Interface.ClipboardTimeout:0.##} seconds.", Severity.Info);
                }
            }
            if (type)
            {
                KeyboardEmulator.EnterText(chosenValue, ConfigManager.Config.Output.DeadKeys);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Asks the user to choose a password file, decrypts it, and copies the resulting value to the clipboard.
        /// </summary>
        public void DecryptPassword(bool copyToClipboard, bool typeUsername, bool typePassword)
        {
            var selectedFile = RequestPasswordFile();

            // If the user cancels their selection, the password decryption should be cancelled too.
            if (selectedFile == null)
            {
                return;
            }

            KeyedPasswordFile passFile;

            try
            {
                passFile = passwordManager.DecryptPassword(selectedFile, ConfigManager.Config.PasswordStore.FirstLineOnly);
            }
            catch (GpgError e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (GpgException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed. " + e.Message);
                return;
            }
            catch (ConfigurationException e)
            {
                notificationService.ShowErrorWindow("Password decryption failed: " + e.Message);
                return;
            }
            catch (Exception e)
            {
                notificationService.ShowErrorWindow($"Password decryption failed: An error occurred: {e.GetType().Name}: {e.Message}");
                return;
            }

            if (copyToClipboard)
            {
                clipboard.Place(passFile.Password, TimeSpan.FromSeconds(ConfigManager.Config.Interface.ClipboardTimeout));
                if (ConfigManager.Config.Notifications.Types.PasswordCopied)
                {
                    notificationService.Raise($"The password has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.Interface.ClipboardTimeout:0.##} seconds.", Severity.Info);
                }
            }
            var usernameEntered = false;

            if (typeUsername)
            {
                var username = new PasswordFileParser().GetUsername(passFile);
                if (username != null)
                {
                    KeyboardEmulator.EnterText(username, ConfigManager.Config.Output.DeadKeys);
                    usernameEntered = true;
                }
            }
            if (typePassword)
            {
                // If a username has also been entered, press Tab to switch to the password field.
                if (usernameEntered)
                {
                    KeyboardEmulator.EnterRawText("{TAB}");
                }

                KeyboardEmulator.EnterText(passFile.Password, ConfigManager.Config.Output.DeadKeys);
            }
        }
Beispiel #12
0
 private Window(SmartProcess process, HWND handle) {
     Process = process;
     Handle = handle;
     Mouse = new RelativeMouseEmulator(this);
     Keyboard = new KeyboardEmulator();
 }
Beispiel #13
0
        /// <summary>
        /// Asks the user to choose a password file, decrypts it,
        /// generates an OTP code from the secret in the totp field, and copies the resulting value to the clipboard.
        /// </summary>
        public void GenerateTotpCode(bool copyToClipboard, bool typeTotpCode)
        {
            var selectedFile = RequestPasswordFile();

            // If the user cancels their selection, the password decryption should be cancelled too.
            if (selectedFile == null)
            {
                return;
            }

            KeyedPasswordFile passFile;

            try
            {
                passFile = passwordManager.DecryptPassword(selectedFile, true);
            }
            catch (Exception e) when(e is GpgError || e is GpgException || e is ConfigurationException)
            {
                notificationService.ShowErrorWindow("TOTP decryption failed: " + e.Message);
                return;
            }
            catch (Exception e)
            {
                notificationService.ShowErrorWindow($"TOTP decryption failed: An error occurred: {e.GetType().Name}: {e.Message}");
                return;
            }

            String secretKey = null;

            foreach (var k in passFile.Keys)
            {
                // totp: Xxxx4
                if (k.Key == "totp")
                {
                    secretKey = k.Value;
                }

                // otpauth: //totp/account?secret=FxxxX&digits=6
                if (k.Key == "otpauth")
                {
                    var regex   = new Regex("secret=([a-zA-Z0-9]+)&", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    var matches = regex.Match(k.Value);
                    if (matches.Success)
                    {
                        secretKey = matches.Groups[1].Value;
                    }
                }
            }

            var foo = String.Join(",", passFile.Keys.Select(f => f.Key));

            if (secretKey == null)
            {
                notificationService.ShowErrorWindow($"TOTP decryption failed: Failed to find an OTP secret. Keys = ${foo}");
                return;
            }

            var secretKeyBytes = Base32Encoding.ToBytes(secretKey);
            var totp           = new Totp(secretKeyBytes);
            var totpCode       = totp.ComputeTotp();

            if (copyToClipboard)
            {
                ClipboardHelper.Place(totpCode, TimeSpan.FromSeconds(ConfigManager.Config.Interface.ClipboardTimeout));
                if (ConfigManager.Config.Notifications.Types.TotpCopied)
                {
                    notificationService.Raise($"The totp code has been copied to your clipboard.\nIt will be cleared in {ConfigManager.Config.Interface.ClipboardTimeout:0.##} seconds.", Severity.Info);
                }
            }

            if (typeTotpCode)
            {
                KeyboardEmulator.EnterText(totpCode, ConfigManager.Config.Output.DeadKeys);
            }
        }