Example #1
0
        public FormMain()
        {
            if (!WindowManager.IsSingleInstance)
            {
                MessageBox.Show(Translations.Get("already_running"));
                Environment.Exit(0);
            }

            PressedKeys = new List <Keys>();
            InitializeComponent();
            HideMainForm();

            this.Text            = Translations.Get("about_text");
            this.Item_Title.Text = Translations.Get("about_title");

            Input              = new GlobalHooker();
            KInput             = new KeyboardHookListener(Input);
            MInput             = new MouseHookListener(Input);
            KInput.Enabled     = true; MInput.Enabled = true;
            MInput.MouseDown  += new MouseEventHandler(OnUserMouseInteraction);
            MInput.MouseUp    += new MouseEventHandler(OnUserMouseInteraction);
            MInput.MouseMove  += new MouseEventHandler(OnUserMouseInteraction);
            MInput.MouseClick += new MouseEventHandler(OnUserMouseClick);
            KInput.KeyDown    += new KeyEventHandler(OnUserKeyboardPress);
            KInput.KeyUp      += new KeyEventHandler(OnUserKeyboardRelease);
            KeySender.KeyStroke(KeySender.VkKeyScan('^'));

            if (File.Exists(SettingsFile.SaveFile))
            {
                SettingsFile.Load(ref ActivateKey);
            }
            else
            {
                SettingsFile.Save(ActivateKey);
                if (MessageBox.Show(
                        String.Format(
                            "{0}\n\n{1}\n{2}\n\n{3}",
                            Translations.Get("welcome_text_1"),
                            Translations.Get("welcome_text_2"),
                            Translations.Get("welcome_text_3"),
                            Translations.Get("welcome_text_4")
                            ),
                        Translations.Get("welcome_title"),
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question
                        ) == DialogResult.Yes)
                {
                    Button_Help_Click(new object(), EventArgs.Empty);
                }
            }

            RefreshFiles();

            WqlEventQuery query = new WqlEventQuery("Select * From __InstanceCreationEvent Within 2 Where TargetInstance Isa 'Win32_Process'");

            watcher = new ManagementEventWatcher(query);
            watcher.EventArrived += new EventArrivedEventHandler(OnWindowOpen);
            watcher.Start();

            ProceedOtherMacros(Keys.None, MacroType.Startup);

            timer          = new System.Windows.Forms.Timer();
            timer.Interval = 1000;
            timer.Tick    += new EventHandler(OnIDLETick);
            timer.Start();
        }
Example #2
0
        private void OnUserKeyboardPress(object sender, KeyEventArgs e)
        {
            idletime = 0;
            if ((int)e.KeyCode == ActivateKey)
            {
                MacroActivate = true;
                if (testing)
                {
                    string name = WindowManager.GetActiveWindowTitle();
                    string exe  = WindowManager.GetActiveWindowExename();
                    TopMostMessageBox.Show(
                        String.Format(Translations.Get("window_info_result_text"), name, exe),
                        Translations.Get("window_info_result_title"));
                    testing = false;
                }
            }

            switch (e.KeyCode)
            {
            case System.Windows.Forms.Keys.LShiftKey:
            case System.Windows.Forms.Keys.RShiftKey:
            case System.Windows.Forms.Keys.Shift:
            case System.Windows.Forms.Keys.ShiftKey:
                shift = true;
                break;
            }

            while (PressedKeys.Contains(e.KeyCode))
            {
                PressedKeys.Remove(e.KeyCode);
            }

            PressedKeys.Add(e.KeyCode);

            if (KeyHelper.Form_Visible)
            {
                KeyHelper.BoxContent += KeyConverter.WinFormKey2Name(e.KeyCode) + "\n";
                e.Handled             = true;
            }
            else if (ProceedRewriteMacros(e.KeyCode))
            {
                e.Handled = true;
            }

            //Handle french ^ and ¨ key modifiers: êâôëü
            if ((int)e.KeyCode == 221 && !circumflex)
            {
                circumflex = true;
                e.Handled  = true;
                if (shift)
                {
                    diaeresis = true;
                }
            }
            else if (circumflex && !circumflexOn)
            {
                circumflexOn = true;
                switch (e.KeyCode)
                {
                case (System.Windows.Forms.Keys) 221:
                    circumflex = false;
                    diaeresis  = false;
                    if (diaeresis)
                    {
                        KeySender.KeyPress(KeyConverter.Name2Key("Shift"));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyRelease(KeyConverter.Name2Key("Shift"));
                    }
                    else
                    {
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                    }
                    break;

                case System.Windows.Forms.Keys.A:
                case System.Windows.Forms.Keys.E:
                case System.Windows.Forms.Keys.I:
                case System.Windows.Forms.Keys.O:
                case System.Windows.Forms.Keys.U:
                case System.Windows.Forms.Keys.Y:
                    if (diaeresis)
                    {
                        KeySender.KeyPress(KeyConverter.Name2Key("Shift"));
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                        KeySender.KeyRelease(KeyConverter.Name2Key("Shift"));
                    }
                    else
                    {
                        KeySender.KeyStroke(KeySender.VkKeyScan('^'));
                    }
                    circumflex = false;
                    diaeresis  = false;
                    break;

                default:
                    circumflex = false;
                    diaeresis  = false;
                    break;
                }
                circumflexOn = false;
            }
        }