Ejemplo n.º 1
0
        private void InitializeKeyboardLayoutMenu()
        {
            //Copy Image List
            cmsLeft.ImageList = imageList;

            //Create Turn Off Menu Item
            KToolStripMenuItem menuItem = new KToolStripMenuItem("Turn Off");
            menuItem.Checked = true;
            menuItem.Click += new EventHandler(cmsLeftMenuItem_Click);
            cmsLeft.Items.Add(menuItem);

            htkyOnOff.Hotkey = new Hotkey(Properties.Settings.Default.TurnOffHotkey);
        }
Ejemplo n.º 2
0
        private void LoadKeyboardLayoutList(bool removeOld)
        {
            if (removeOld)
            {
                lvLayouts.Items.Clear();

                ToolStripItem defItem = cmsLeft.Items[0];
                cmsLeft.Items.Clear();
                cmsLeft.Items.Add(defItem);
                ActiveKeyboardList.Clear();
                ActiveKeyboardList.Add(DefaultLayout);
            }

            KeyboardLayoutList keyboardList = new KeyboardLayoutList();

            FileStream fs = null;
            System.Xml.XmlReader reader = null;

            try
            {
                fs = new FileStream(layoutXMLFile, FileMode.Open, FileAccess.Read);
                reader = System.Xml.XmlReader.Create(fs);

                reader.MoveToContent();
                if (reader.LocalName == "Layouts")
                {
                    reader.ReadStartElement("Layouts");
                    keyboardList.ReadXml(reader);
                    reader.ReadEndElement();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                if (reader != null) reader.Close();
                if (fs != null) fs.Close();
            }

            //long lPtr = DllPtrHotkeys.ToInt64();
            List<Hotkey> hotkeys = new List<Hotkey>();
            hotkeys.Add(htkyOnOff.Hotkey);

            foreach (KeyboardLayout layout in keyboardList)
            {
                KeyMagicDotNet.InfoList infoList = KeyMagicDotNet.KeyMagicKeyboard.GetInfosFromKeyboardFile(GetSaveKeyboardPath(layout.file));
                ListViewItem lvItem = new ListViewItem(layout.file);

                hotkeys.Add(new Hotkey(layout.hotkey));

                lvItem.SubItems.Add(layout.display);
                lvItem.SubItems.Add(layout.hotkey);
                lvItem.SubItems.Add(KeyMagicDotNet.KeyMagicKeyboard.GetVersion(GetSaveKeyboardPath(layout.file)).ToString());
                lvItem.SubItems.Add(infoList.GetDescription());
                using (Bitmap bmIcon = infoList.GetIcon())
                {
                    if (bmIcon != null)
                    {
                        imageList.Images.Add(layout.file, bmIcon);
                        lvItem.ImageKey = layout.file;
                    }
                    if (layout.enable)
                    {
                        ActiveKeyboardList.Add(layout);

                        lvItem.Group = lvLayouts.Groups["Enabled"];
                        KToolStripMenuItem menuItem = new KToolStripMenuItem(layout.display);
                        if (bmIcon != null)
                            using (Icon icon = Icon.FromHandle(bmIcon.GetHicon()))
                            {
                                iconList[layout.file] = menuItem.Icon = icon;
                            }
                        else iconList[layout.file] = defaultKeyboardIcon;

                        menuItem.ImageKey = lvItem.ImageKey;
                        menuItem.ShortcutKeyDisplayString = layout.hotkey;
                        String fontFamily = infoList.GetFontFamily();
                        menuItem.Click += new EventHandler(cmsLeftMenuItem_Click);
                        cmsLeft.Items.Add(menuItem);
                    }
                    else
                    {
                        lvItem.Group = lvLayouts.Groups["Disabled"];
                    }
                }
                lvLayouts.Items.Add(lvItem);
            }

            keyEventHandler.Hotkeys = hotkeys.ToArray();
        }
Ejemplo n.º 3
0
        private bool AddKeyboardLayoutToListWithFile(string fileName)
        {
            try
            {
                KeyMagicDotNet.InfoList infoList = KeyMagicDotNet.KeyMagicKeyboard.GetInfosFromKeyboardFile(fileName);
                if (infoList == null)
                {
                    MessageBox.Show(this, "Keyboard layout file cannot be loaded.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }
                string fileTitle = Path.GetFileNameWithoutExtension(fileName);
                ListViewItem lvItem = new ListViewItem(fileTitle);
                lvItem.Group = lvLayouts.Groups["Enabled"];

                Bitmap icon = infoList.GetIcon();
                if (icon != null)
                {
                    imageList.Images.Add(fileTitle, icon);
                    lvItem.ImageKey = fileTitle;
                }
                else
                {
                    lvItem.ImageKey = "DefaultIcon";
                }

                String name = infoList.GetName();
                if (name != null)
                {
                    lvItem.SubItems.Add(name);
                }
                else
                {
                    lvItem.SubItems.Add(fileTitle);
                }

                String hotkey = infoList.GetHotkey();
                if (hotkey != null)
                {
                    lvItem.SubItems.Add(new Hotkey(hotkey).ToString());
                }
                else
                {
                    lvItem.SubItems.Add("");
                }

                lvItem.SubItems.Add(KeyMagicDotNet.KeyMagicKeyboard.GetVersion(fileName).ToString());

                String desc = infoList.GetDescription();
                if (desc != null)
                {
                    lvItem.SubItems.Add(desc);
                }
                else
                {
                    lvItem.SubItems.Add("");
                }

                KToolStripMenuItem menuItem = new KToolStripMenuItem(lvItem.Text);
                menuItem.ImageKey = lvItem.ImageKey;
                menuItem.Click += new EventHandler(cmsLeftMenuItem_Click);

                try
                {
                    File.Copy(fileName, GetSaveKeyboardPath(fileTitle));
                    lvLayouts.Items.Add(lvItem);
                    //cmsLeft.Items.Add(menuItem);
                }
                catch (UnauthorizedAccessException ex)
                {
                    if (!isAdmin)
                    {
                        AskToRunAsAdministrator("Access is denied and failed to copy keyboard layout file. Do you want to run KeyMagic as administrator?");
                    }
                    else
                    {
                        MessageBox.Show(this, ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    return false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return false;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            return true;
        }