Exemplo n.º 1
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // When the app exits we need to un-shift any modify keys that might
                // have been pressed or they'll still be stuck after exit
                Logger.Instance.Log4.Debug("Ensuring shift key modifiers are reset...");
                SendInputCommand.ShiftKey("shift", false);
                SendInputCommand.ShiftKey("ctrl", false);
                SendInputCommand.ShiftKey("alt", false);
                SendInputCommand.ShiftKey("lwin", false);
                SendInputCommand.ShiftKey("rwin", false);

                components?.Dispose();

                if (Server != null)
                {
                    // remove our notification handler
                    Server.Notifications -= serverSocketCallbackHandler;
                    Server.Dispose();
                }
                if (Client != null)
                {
                    // remove our notification handler
                    Client.Notifications -= clientSocketNotificationHandler;
                    Client.Dispose();
                }

                if (SerialServer != null)
                {
                    SerialServer.Notifications -= HandleSerialServerNotifications;
                    SerialServer.Dispose();
                }

                UpdateService.Instance.GotLatestVersion -= UpdateService_GotLatestVersion;
            }
            base.Dispose(disposing);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // When the app exits we need to un-shift any modify keys that might
                // have been pressed or they'll still be stuck after exit
                SendInputCommand.ShiftKey("shift", false);
                SendInputCommand.ShiftKey("ctrl", false);
                SendInputCommand.ShiftKey("alt", false);
                SendInputCommand.ShiftKey("lwin", false);
                SendInputCommand.ShiftKey("rwin", false);

                if (components != null)
                {
                    components.Dispose();
                }

                if (_server != null)
                {
                    // remove our notification handler
                    _server.Notifications -= HandleSocketServerCallbacks;
                    _server.Dispose();
                }
                if (_client != null)
                {
                    // remove our notification handler
                    _client.Notifications -= HandleClientNotifications;
                    _client.Dispose();
                }

                if (_serialServer != null)
                {
                    _serialServer.Notifications -= HandleSerialServerNotifications;
                    _serialServer.Dispose();
                }
            }
            base.Dispose(disposing);
        }
Exemplo n.º 3
0
        public void Execute(Reply reply, String cmd)
        {
            if (!MainWindow.MainWnd.Settings.DisableInternalCommands)
            {
                if (cmd.StartsWith(McecCommand.CmdPrefix))
                {
                    var command = new McecCommand(cmd);
                    command.Execute(reply);
                    return;
                }

                if (cmd.StartsWith("chars:"))
                {
                    // "chars:<chars>
                    String chars = Regex.Unescape(cmd.Substring(6, cmd.Length - 6));
                    MainWindow.AddLogEntry(String.Format("Cmd: Sending {0} chars: {1}", chars.Length, chars));
                    var sim = new InputSimulator();
                    sim.Keyboard.TextEntry(chars);
                    return;
                }

                if (cmd.StartsWith("api:"))
                {
                    // "api:API(params)
                    // TODO: Implement API stuff
                    return;
                }

                if (cmd.StartsWith("shiftdown:"))
                {
                    // Modifyer key down
                    SendInputCommand.ShiftKey(cmd.Substring(10, cmd.Length - 10), true);
                    return;
                }

                if (cmd.StartsWith("shiftup:"))
                {
                    // Modifyer key up
                    SendInputCommand.ShiftKey(cmd.Substring(8, cmd.Length - 8), false);
                    return;
                }

                if (cmd.StartsWith(MouseCommand.CmdPrefix))
                {
                    // mouse:<action>[,<parameter>,<parameter>]
                    var mouseCmd = new MouseCommand(cmd);
                    mouseCmd.Execute(reply);
                    return;
                }

                if (cmd.Length == 1)
                {
                    // It's a single character, just send it
                    // must be upper case (VirtualKeyCode codes are for upper case)
                    cmd = cmd.ToUpper();
                    char c = cmd.ToCharArray()[0];

                    var sim = new InputSimulator();

                    MainWindow.AddLogEntry("Cmd: Sending keydown for: " + cmd);
                    sim.Keyboard.KeyPress((VirtualKeyCode)c);
                    return;
                }
            }

            // Command is in MCEControl.commands
            if (_hashTable.ContainsKey(cmd.ToUpper()))
            {
                Command command = FindKey(cmd.ToUpper());
                command.Execute(reply);
            }
            else
            {
                MainWindow.AddLogEntry("Cmd: Unknown Cmd: " + cmd);
            }
        }