Ejemplo n.º 1
0
        /// <summary>
        /// Initialize the application
        /// </summary>
        void Init()
        {
            //create instances
            keySimulator   = new KeyboardSimulator();
            keyMonitor     = new KeyboardMonitor();
            commandCapture = new StringBuilder();

            //initialize ui
            liveStats = new LiveStatsUI();
            InitNotify();

            //load commands
            commands = BlazeCommands.FromFile(CommandsFile);
            if (commands == null)
            {
                //MessageBox.Show($"Could not load Commands from \n{CommandsFile}", "Cannot Load Commands", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();

                //load default commands
                File.Copy(DEFAULT_COMMANDS_FILE, CommandsFile);
                commands = BlazeCommands.FromFile(CommandsFile);
                SendNotification("Default Commands were loaded!");
            }

            //sanity- check: commands should be loaded by now
            if (commands == null)
            {
                return;
            }

            //initialize monitor
            keyMonitor.Init();
            keyMonitor.KeyPressed += OnGlobalKeyPress;

            AfterInit();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// initializes the notify icon
        /// </summary>
        void InitNotify()
        {
            //create menu
            ContextMenu context = new ContextMenu();

            context.MenuItems.Add("Edit Commands", (ts, te) =>
            {
                //open commands.blaze file in editor
                Process editor             = Process.Start("notepad", CommandsFile);
                editor.EnableRaisingEvents = true;
                editor.Exited += (xs, xe) =>
                {
                    //reload commands
                    commands = BlazeCommands.FromFile(CommandsFile);
                    SendNotification("Commands File was reloaded!");
                    editor.Dispose();
                };
            });
            context.MenuItems.Add("Autostart App", (s, e) =>
            {
                //get sender as menuitem
                MenuItem sender = s as MenuItem;
                if (sender == null)
                {
                    return;
                }

                //toggle auto- start state
                bool autoEn = GetAutoStartEnabled();
                RegisterAutostart(!autoEn);
                sender.Checked = !autoEn;
            });
            context.MenuItems.Add("Live Stats", (s, e) =>
            {
                //show live stats window
                liveStats.Show();
            });
            context.MenuItems.Add("Exit App", (s, e) =>
            {
                //exit the app
                Application.Exit();
            });

            //create icon
            notifyIcon = new NotifyIcon()
            {
                Icon        = Properties.Resources.app_icon,
                Text        = NOTIFY_TITLE,
                ContextMenu = context
            };

            //make icon visible
            notifyIcon.Visible = true;

            //allows notifications
            notifyIcon.BalloonTipClosed += (s, e) =>
            {
                notifyIcon.Visible = false;
                notifyIcon.Visible = true;
            };
        }