public bool Save(KeyCommand command)
        {
            bool       flag   = true;
            TextWriter writer = new StreamWriter(_fileName, true);

            try
            {
                string commandString = "";

                commandString =
                    (command.CTRLMask ? "1" : "0") + "<|>" +
                    (command.ShiftMask ? "1" : "0") + "<|>" +
                    (command.ALTMask ? "1" : "0") + "<|>" +
                    (command.WINMask ? "1" : "0") + "<|>" +
                    ((int)command.Key).ToString() + "<@>" +
                    command.SendKey + "<@>" +
                    command.ExecString + "<@>" +
                    command.KeyName;

                writer.WriteLine(commandString);
            }
            catch
            {
                flag = false;
            }
            finally
            {
                writer.Close();
            }
            return(flag);
        }
        public static Hotkey BindHotKey(KeyCommand keyCommand)
        {
            Hotkey hotKey = new Hotkey(keyCommand.Key, keyCommand.ShiftMask, keyCommand.CTRLMask,
                                       keyCommand.ALTMask, keyCommand.WINMask, keyCommand.SendKey, keyCommand.ExecString, keyCommand.KeyName);

            return(hotKey);
        }
Example #3
0
        private Hotkey BindHotKey(KeyCommand keyCommand)
        {
            Hotkey hotKey = Common.BindHotKey(keyCommand);

            hotKey.Register(new Label());
            hotKey.Pressed += new HandledEventHandler(HandleHotKeyPress);

            return(hotKey);
        }
Example #4
0
 private void RemoveKeyCommand()
 {
     if (dgvCommands.SelectedCells.Count > 0)
     {
         int        rowIndex = dgvCommands.SelectedCells[0].RowIndex;
         KeyCommand command  = (KeyCommand)dgvCommands.Rows[rowIndex].DataBoundItem;
         manager.KeyCommandCollection.Remove(command);
         BindData();
     }
 }
Example #5
0
 private void AssignControls(KeyCommand commandObject)
 {
     chkALT.Checked   = commandObject.ALTMask;
     chkCTRL.Checked  = commandObject.CTRLMask;
     chkShift.Checked = commandObject.ShiftMask;
     chkWin.Checked   = commandObject.WINMask;
     txtChar.Text     = ((char)commandObject.Key).ToString();
     chkSK.Checked    = commandObject.SendKey.Trim() != "";
     chkExec.Checked  = commandObject.ExecString.Trim() != "";
     txtSK.Text       = commandObject.SendKey.Trim();
     txtExec.Text     = commandObject.ExecString.Trim();
     txtKeyName.Text  = commandObject.KeyName.Trim();
 }
Example #6
0
        private KeyCommand GetSaveObject()
        {
            KeyCommand command = new KeyCommand();

            command.CTRLMask   = chkCTRL.Checked;
            command.ShiftMask  = chkShift.Checked;
            command.ALTMask    = chkALT.Checked;
            command.WINMask    = chkWin.Checked;
            command.Key        = (Keys)((int)txtChar.Text.ToCharArray()[0]);
            command.SendKey    = chkSK.Checked ? txtSK.Text.Trim() : "";
            command.ExecString = chkExec.Checked ? txtExec.Text.Trim() : "";
            command.KeyName    = txtKeyName.Text.Trim();

            return(command);
        }
Example #7
0
        private void dgvCommands_DoubleClick(object sender, EventArgs e)
        {
            if (dgvCommands.SelectedCells.Count == 0)
            {
                return;
            }
            editRowIndex = dgvCommands.SelectedCells[0].RowIndex;

            //if (editRowIndex == 0) return; // Header Row

            editObject = (KeyCommand)dgvCommands.Rows[dgvCommands.SelectedCells[0].RowIndex].DataBoundItem;

            AssignControls(editObject);

            _editMode = true;
        }
Example #8
0
        private void FormatGrid()
        {
            dgvCommands.Columns[0].Width = Convert.ToInt32(dgvCommands.Width * 0.38);
            dgvCommands.Columns[1].Width = Convert.ToInt32(dgvCommands.Width * 0.57);

            dgvCommands.Columns[2].Visible = false;
            dgvCommands.Columns[3].Visible = false;
            dgvCommands.Columns[4].Visible = false;
            dgvCommands.Columns[5].Visible = false;
            dgvCommands.Columns[6].Visible = false;
            dgvCommands.Columns[7].Visible = false;
            dgvCommands.Columns[8].Visible = false;
            dgvCommands.Columns[9].Visible = false;



            foreach (DataGridViewRow dgvRow in dgvCommands.Rows)
            {
                KeyCommand keyCurrent = (KeyCommand)dgvRow.DataBoundItem;

                if (keyCurrent != null)
                {
                    dgvRow.Cells["fldShortcut"].Value = keyCurrent.ToString();
                    dgvRow.Cells["fldKeyName"].Value  = keyCurrent.KeyName;
                }
            }



            //DataGridViewColumn dgvCol = new DataGridViewColumn();
            //dgvCol.Name = "fldShortcut";
            //dgvCol.DisplayIndex = 0;
            //dgvCol.HeaderText = "Shortcut";

            //dgvCommands.Columns.Add(dgvCol);

            //dgvCol = new DataGridViewColumn();
            //dgvCol.Name = "fldKeyName";
            //dgvCol.DisplayIndex = 1;
            //dgvCol.HeaderText = "Key Name";
            //dgvCommands.Columns.Add(dgvCol);
        }
Example #9
0
        private void ConstructKeyCommandString()
        {
            KeyCommand command = new KeyCommand();

            if (chkALT.Checked)
            {
                command.ALTMask = true;
            }
            if (chkCTRL.Checked)
            {
                command.CTRLMask = true;
            }
            if (chkShift.Checked)
            {
                command.ShiftMask = true;
            }
            if (chkWin.Checked)
            {
                command.WINMask = true;
            }

            if (txtChar.Text.Trim() != "")
            {
                command.Key = (Keys)((int)txtChar.Text.ToCharArray()[0]);
            }

            if (command.ToString().Trim() == "+")
            {
                lblKeyComb.Text = "";
            }
            else
            {
                lblKeyComb.Text = command.ToString();
            }

            if (lblKeyComb.Text.Trim().EndsWith("+"))
            {
                lblKeyComb.Text = lblKeyComb.Text.Substring(0, lblKeyComb.Text.Length - 2).Trim();
            }

            command = null;
        }
        public List <KeyCommand> GetCollection()
        {
            TextReader        reader        = new StreamReader(_fileName);
            List <KeyCommand> cmdCollection = new List <KeyCommand>();

            string readLine = reader.ReadLine();


            while (readLine != null)
            {
                KeyCommand cmd = new KeyCommand(readLine);
                if (cmd.Key != Keys.None)
                {
                    cmdCollection.Add(cmd);
                }
                readLine = reader.ReadLine();
            }
            reader.Close();
            return(cmdCollection);
        }
Example #11
0
        private bool CheckDuplication(KeyCommand commandObject)
        {
            var query = from KeyCommand command in manager.KeyCommandCollection
                        where command.ToString() == commandObject.ToString()
                        select command;

            if (query.Count() > 0)
            {
                if (_editMode)
                {
                    return(editObject.ToString() == commandObject.ToString());
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
        public DataTable GetCollectionTable()
        {
            TextReader reader = new StreamReader(_fileName);

            string readLine = reader.ReadLine();

            DataTable _dt = new DataTable();

            _dt.Columns.Add("CTRL", typeof(string));
            _dt.Columns.Add("SHIFT", typeof(string));
            _dt.Columns.Add("ALT", typeof(string));
            _dt.Columns.Add("WIN", typeof(string));
            _dt.Columns.Add("KeyName", typeof(string));
            _dt.Columns.Add("Send", typeof(string));
            _dt.Columns.Add("App", typeof(string));

            DataRow _dr;

            while (readLine != null)
            {
                KeyCommand cmd = new KeyCommand(readLine);

                _dr            = _dt.NewRow();
                _dr["CTRL"]    = cmd.CTRLMask ? "YES" : "NO";
                _dr["SHIFT"]   = cmd.CTRLMask ? "YES" : "NO";
                _dr["ALT"]     = cmd.CTRLMask ? "YES" : "NO";
                _dr["WIN"]     = cmd.CTRLMask ? "YES" : "NO";
                _dr["Send"]    = cmd.SendKey;
                _dr["App"]     = cmd.ExecString;
                _dr["KeyName"] = cmd.KeyName;
                _dt.Rows.Add(_dr);

                readLine = reader.ReadLine();
            }

            reader.Close();

            return(_dt);
        }
Example #13
0
        private List <KeyCommand> GetKeyCommands(string fileName)
        {
            StreamWriter writer = null;

            if (!File.Exists(fileName))
            {
                writer = File.CreateText(fileName);
                writer.Close();
                CreateDefaultEntries(fileName);
            }

            hotKeyList = new List <Hotkey>();
            //hotKeyList.RemoveAll(PredicateDelegate);

            manager = new KeyCommandManager(fileName);

            WriteEntry("Binding Keys");

            if (manager.KeyCommandCollection.Count > 0)
            {
                foreach (KeyCommand command in manager.KeyCommandCollection)
                {
                    MaintainHotKey(BindHotKey(command));
                }
            }
            else
            {
                // New conf file creation
                KeyCommand newCommand;
                if (File.Exists(Application.StartupPath + "\\PS.EN.DE.exe"))
                {
                    //E:\Projects\PS.EN.DE\PS.EN.DE\bin\Debug\PS.EN.DE.exe<!args!>c noui
                    //new Hotkey(Keys.Z, true, true, true, false, "", Application.StartupPath + "\\PS.EN.DE.exe<!args!>c noui", "Lentracs Decypher");

                    WriteEntry("Creating Hot Key For Encryptor");
                    newCommand            = new KeyCommand();
                    newCommand.KeyName    = "Lentracs Decypher";
                    newCommand.Key        = Keys.Z;
                    newCommand.CTRLMask   = true;
                    newCommand.ALTMask    = true;
                    newCommand.ShiftMask  = true;
                    newCommand.WINMask    = false;
                    newCommand.ExecString = Application.StartupPath + "\\PS.EN.DE.exe<!args!>c noui";
                    newCommand.SendKey    = "";

                    manager.Save(newCommand);
                }
                if (File.Exists(Application.StartupPath + "\\TrackInfo.exe"))
                {
                    //E:\Projects\PS.EN.DE\PS.EN.DE\bin\Debug\PS.EN.DE.exe<!args!>c noui
                    //new Hotkey(Keys.Z, true, true, true, false, "", Application.StartupPath + "\\PS.EN.DE.exe<!args!>c noui", "Lentracs Decypher");

                    WriteEntry("Creating Hot Key For TrackInfo");
                    newCommand            = new KeyCommand();
                    newCommand.KeyName    = "TrackInfo";
                    newCommand.Key        = Keys.T;
                    newCommand.CTRLMask   = true;
                    newCommand.ALTMask    = true;
                    newCommand.ShiftMask  = true;
                    newCommand.WINMask    = false;
                    newCommand.ExecString = Application.StartupPath + "\\TrackInfo.exe";
                    newCommand.SendKey    = "";

                    manager.Save(newCommand);
                }
            }

            return(manager.KeyCommandCollection);

            #region Old Commented



            //TextReader reader = new StreamReader(fileName);

            //List<KeyCommand> keyCommandList = new List<KeyCommand>();

            //string readLine = reader.ReadLine();
            //while (readLine != null)
            //{
            //    KeyCommand keyCommandObject = new KeyCommand(readLine);
            //    if (keyCommandObject.Key != Keys.None)
            //    {
            //        hotKeyList.Add(BindHotKey(keyCommandObject));
            //        keyCommandList.Add(keyCommandObject);
            //    }
            //    readLine = reader.ReadLine();
            //}
            //reader.Close();

            //return keyCommandList;

            #endregion
        }
Example #14
0
        private bool Validation()
        {
            if (txtKeyName.Text.Trim() == "")
            {
                MessageBox.Show("Empty Key Name", "Validation failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtChar.Focus();
                return(false);
            }

            if (txtChar.Text.Trim() == "")
            {
                MessageBox.Show("Empty Character", "Validation failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtChar.Focus();
                return(false);
            }
            if (!chkSK.Checked && !chkExec.Checked)
            {
                MessageBox.Show("Specify an action to be performed", "Validation failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (!chkSK.Checked)
                {
                    chkSK.Focus();
                }
                else if (!chkExec.Checked)
                {
                    chkExec.Focus();
                }
                return(false);
            }
            if (chkSK.Checked && txtSK.Text.Trim() == "")
            {
                MessageBox.Show("Empty Send Keys", "Validation failed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSK.Focus();
                return(false);
            }
            if (chkExec.Checked && txtExec.Text.Trim() == "")
            {
                MessageBox.Show("Empty Application path", "Validation failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtExec.Focus();
                return(false);
            }
            KeyCommand tmpObject = GetSaveObject();

            //if (!CheckDuplication(tmpObject))
            //{
            //    MessageBox.Show("Hotkey Registered Already", "Validation failed",
            //           MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    chkCTRL.Focus();
            //    return false;
            //}



            if (!CheckExistence(tmpObject.ToString(), false, _editMode)) // Hot key exists in deleted records
            {
                if (!tmpObject.CanRegister())
                {
                    MessageBox.Show("Error Registering Hotkey", "Validation failed",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    chkCTRL.Focus();
                    return(false);
                }
            }

            if (CheckExistence(txtKeyName.Text, true, _editMode))
            {
                MessageBox.Show("A Key name already exists.", "Validation failed",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                chkCTRL.Focus();
                return(false);
            }

            return(true);
        }