当前位置: 首页>>代码示例>>C#>>正文


C# KeysConverter.ConvertFromString方法代码示例

本文整理汇总了C#中System.Windows.Forms.KeysConverter.ConvertFromString方法的典型用法代码示例。如果您正苦于以下问题:C# KeysConverter.ConvertFromString方法的具体用法?C# KeysConverter.ConvertFromString怎么用?C# KeysConverter.ConvertFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Forms.KeysConverter的用法示例。


在下文中一共展示了KeysConverter.ConvertFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: keyPress

        // I don't like that mouse buttons are handled here. This will be fixed later.
        public void keyPress(string rawKey, int hold = 0)
        {
            if (rawKey.Contains("M_"))
            {
                switch (rawKey)
                {
                    case ("M_1"):
                        Mouse.PressButton(Mouse.MouseKeys.Left);
                        break;
                    case ("M_2"):
                        Mouse.PressButton(Mouse.MouseKeys.Right);
                        break;
                    case ("M_3"):
                        Mouse.PressButton(Mouse.MouseKeys.Middle);
                        break;
                    default:
                        Console.WriteLine("Invalid Mouse Button Press");
                        break;

                }
            }
            else
            {
                KeysConverter kc = new KeysConverter();
                Keys key = (Keys)kc.ConvertFromString(rawKey);

                if (hold == 0)
                    Keyboard.KeyPress(key, 5);
                else if (hold == 1)
                    Keyboard.KeyDown(key);
                else
                    Keyboard.KeyUp(key);
            }
        }
开发者ID:j0z,项目名称:PlayM,代码行数:35,代码来源:InputSynth.cs

示例2: Preferences

 public Preferences()
 {
     KeysConverter k = new KeysConverter();
     Properties.Settings s = Properties.Settings.Default;
     s.Reload();
     if (s.UID == 0)
     {
         //s.UID = new Random().Next(10000);
         //while (!uploader.InitializeUID(s.UID.ToString(), ""))
         //    s.UID = new Random().Next(10000);
         UID setID = new UID();
         if (setID.ShowDialog()==DialogResult.OK)
             s.UID = setID.ID;
     }
     _sc1 = (Keys)k.ConvertFromString(s.Shortcut_1);
     _sc2 = (Keys)k.ConvertFromString(s.Shortcut_2);
     _sc3 = (Keys)k.ConvertFromString(s.Shortcut_3);
 }
开发者ID:ajansen7,项目名称:Pointing-Magnifier,代码行数:18,代码来源:Preferences.cs

示例3: InitializeHotKeys

        private void InitializeHotKeys()
        {
            var kc = new SWF.KeysConverter();
            var mkc = new ModifierKeysConverter();

            _sshHotkey = new HotKey((ModifierKeys)mkc.ConvertFromString(_config.Hotkeys.Select.Modifiers), (SWF.Keys)kc.ConvertFromString(_config.Hotkeys.Select.Key));
            _sshHotkey.HotKeyPressed += k => ((MainWindow)this.MainWindow).ShowFullscreenWindow();

            Exit += (s, e) =>
            {
                _sshHotkey.Dispose();
            };
        }
开发者ID:zerkms,项目名称:shary,代码行数:13,代码来源:App.xaml.cs

示例4: ReadKey

 public Keys ReadKey(string section, string key, Keys defaultValue)
 {
     try
     {
         KeysConverter kc = new KeysConverter();
         Keys k = (Keys)kc.ConvertFromString(Read(section, key));
         return k;
     }
     catch (Exception e)
     {
         return defaultValue;
     }
 }
开发者ID:StrayDev,项目名称:Stray.Common,代码行数:13,代码来源:INIFile.cs

示例5: Main

        /// <summary>
        /// In the main method, we attempt to read all the information from the .ini file. To convert a string to a System.Windows.Forms.Keys, we use a KeyConverter.
        /// Do not forget to add a reference to System.Windows.Forms, which can be done via project> add reference> assemblies> framework.
        /// I also added using System.Windows.Keys; at the beginning of the project so we don't have to type that every time we use one of its methods.
        /// </summary>
        public static void Main()
        {
            //A keysconverter is used to convert a string to a key.
            KeysConverter kc = new KeysConverter();

            //We create two variables: one is a System.Windows.Keys, the other is a string.
            Keys myKeyBinding;
            string playerName;
            

            //Use a try/catch, because reading values from files is risky: we can never be sure what we're going to get and we don't want our plugin to crash.
            try
            {
                //We assign myKeyBinding the value of the string read by the method getMyKeyBinding(). We then use the kc.ConvertFromString method to convert this to a key.
                //If the string does not represent a valid key (see .ini file for a link) an exception is thrown. That's why we need a try/catch.
                myKeyBinding = (Keys)kc.ConvertFromString(getMyKeyBinding());

                //For the playerName, we don't need to convert the value to a Key, so we can simply assign playerName to the return value of getPlayerName(). 
                //Remember we've already made sure the name can't be longer than 12 characters.
                playerName = getPlayerName();
            }
            //If there was an error reading the values, we set them to their defaults. We also let the user know via a notification.
            catch
            {
                myKeyBinding = Keys.B;
                playerName = "DefaultName";
                Game.DisplayNotification("There was an error reading the .ini file. Setting defaults...");
            }

            //Now you can do whatever you like with them! To finish off the example, we create a notification with our name when we press our keybinding.

            //We create a new GameFiber to listen for our key input. 
            GameFiber.StartNew(delegate
            {
                //This loop runs until it's broken
                while (true)
                {
                    //If our key has been pressed
                    if (Game.IsKeyDown(myKeyBinding))
                    {
                        //Create a notification displaying our name.
                        Game.DisplayNotification("Your name is: " + playerName + ".");
                        //And break out of the loop.
                        break;
                    }

                    //Let other GameFibers do their job by sleeping this one for a bit.
                    GameFiber.Yield();
                }
            });
        }
开发者ID:alexguirre,项目名称:LSPDFR-API,代码行数:56,代码来源:EntryPoint.cs

示例6: SaveKeymapToSettings

        private void SaveKeymapToSettings()
        {
            KeysConverter keysConverter = new KeysConverter();

            Properties.CustomKeys.Default.BackUp = (Keys)keysConverter.ConvertFromString(comboBoxBackUp.SelectedItem.ToString());
            Properties.CustomKeys.Default.BackLeft = (Keys)keysConverter.ConvertFromString(comboBoxBackLeft.SelectedItem.ToString()) ;
            Properties.CustomKeys.Default.BackRight = (Keys)keysConverter.ConvertFromString(comboBoxBackRight.SelectedItem.ToString());

            Properties.CustomKeys.Default.MidUp = (Keys)keysConverter.ConvertFromString(comboBoxMidUp.SelectedItem.ToString());
            Properties.CustomKeys.Default.MidDown = (Keys)keysConverter.ConvertFromString(comboBoxMidDown.SelectedItem.ToString());
            Properties.CustomKeys.Default.MidLeft = (Keys)keysConverter.ConvertFromString(comboBoxMidLeft.SelectedItem.ToString());
            Properties.CustomKeys.Default.MidRight = (Keys)keysConverter.ConvertFromString(comboBoxMidRight.SelectedItem.ToString());

            Properties.CustomKeys.Default.Push = (Keys)keysConverter.ConvertFromString(comboBoxMidPush.SelectedItem.ToString());

            Properties.CustomKeys.Default.Save();
        }
开发者ID:Johnsel,项目名称:KinEmote,代码行数:17,代码来源:CustomKeySetup.cs

示例7: Parse

 public static HotKey Parse(string str)
 {
     HotKey hotKey = new HotKey();
     hotKey.Ctrl = str.Contains("Ctrl");
     hotKey.Alt = str.Contains("Alt");
     hotKey.Shift = str.Contains("Shift");
     hotKey.Win = str.Contains("Win");
     string[] definitions = str.Split('+');
     string key = definitions[definitions.Length - 1];
     KeysConverter converter = new KeysConverter();
     try
     {
         hotKey.Key = (Keys)converter.ConvertFromString(key);
     }
     catch
     { hotKey.Key = DefaultKey; }
     return hotKey;
 }
开发者ID:gayancc,项目名称:lazycure-code,代码行数:18,代码来源:HotKey.cs

示例8: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            /*
            System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            byte[] buffer = System.Text.Encoding.UTF8.GetBytes("test");
            byte[] hashBytes = md5.ComputeHash(buffer);
            string hash = BitConverter.ToString(hashBytes).Replace("-", "");
            //string hash = System.Text.Encoding.UTF8.GetString(hashBytes);
            Console.WriteLine(hash);
             * */

            /*
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"GNTP/(?<Version>.\..)\s+(?<Directive>\S+)\s+(((?<EncryptionAlgorithm>\S+):(?<IV>\S+))\s+|((?<EncryptionAlgorithm>\S+)\s+))(?<KeyHashAlgorithm>(\S+)):(?<KeyHash>(\S+))\s*[\r\n]");
            string s = "GNTP/1.0 REGISTER AES:12345 MD5:12345\r\n";
            System.Text.RegularExpressions.Match m = r.Match(s);
            Console.WriteLine(m.Success);
            Console.WriteLine(m.Groups["EncryptionAlgorithm"].Value);
            Console.WriteLine(m.Groups["IV"].Value);

            s = "GNTP/1.0 REGISTER NONE MD5:12345\r\n";
            m = r.Match(s);
            Console.WriteLine(m.Success);
            Console.WriteLine(m.Groups["EncryptionAlgorithm"].Value);
            Console.WriteLine(m.Groups["IV"].Value);
             * */

            KeysConverter kc = new KeysConverter();
            object k = kc.ConvertFromString("Ctrl+Shift+A");
            Keys keys = (Keys)k;
            Console.WriteLine(keys);
            Console.WriteLine(keys == Keys.A);
            Console.WriteLine(keys == Keys.B);
            Console.WriteLine(keys == Keys.Shift);
            Console.WriteLine(keys == Keys.Control);
            Console.WriteLine(keys == (Keys.A | Keys.Shift | Keys.Control));
            Console.WriteLine(keys == (Keys.B | Keys.Shift | Keys.Control));
        }
开发者ID:iwaim,项目名称:growl-for-windows,代码行数:37,代码来源:Form1.cs

示例9: printAreaButtonTextBox_TextChanged

 private void printAreaButtonTextBox_TextChanged(object sender, EventArgs e)
 {
     if (printScreenTextBox.Text.Length == 1)
     {
         string key = printScreenTextBox.Text.ToUpper();
         Console.WriteLine(key);
         KeysConverter keysConverter = new KeysConverter();
         _printAreaKeyGroup.AddKey((Keys)keysConverter.ConvertFromString(key));
        
     }
 }
开发者ID:NAndreasson,项目名称:Screenie,代码行数:11,代码来源:GUIForm.cs

示例10: Print

 public static void Print(string text) {
     KeysConverter kv = new KeysConverter();
     kv.ConvertFromString("abc");
 }
开发者ID:Nucs,项目名称:nlib,代码行数:4,代码来源:KeyboardSimulator.cs

示例11: ReadOptions

        public static VTankOptions ReadOptions()
        {
            bool doCommit = false;
            VTankOptions options = new VTankOptions();
            KeysConverter kc = new KeysConverter();

            VideoOptions defaultVideo = getDefaultVideoOptions();
            AudioOptions defaultAudio = getDefaultAudioOptions();
            GamePlayOptions defaultGame = getDefaultGamePlayOptions();
            KeyBindings defaultKeys = getDefaultKeyBindings();

            string filename = GetConfigFilePath();
            if (!File.Exists(filename))
                doCommit = true;
            Xmlconfig config = new Xmlconfig(filename, true);
            try
            {
                if (config.Settings.Name == "configuration")
                {
                    // Old configuration file. Port to new configuration type.
                    config.NewXml("xml");
                    doCommit = true;
                    ConvertFromLegacyConfig(config, filename);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Warning: Your old configuration settings have been lost due to an unforeseen error.",
                    "Old configuration settings lost!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Configure options.
            // Format: options.Key = Get(config, "Key", "DefaultValue");
            options.ServerAddress = Get(config, "ServerAddress", "glacier2a.cis.vtc.edu");
            options.ServerPort = Get(config, "ServerPort", "4063");
            options.DefaultAccount = Get(config, "DefaultAccount");
            options.MapsFolder = Get(config, "MapsFolder", "maps");
            options.videoOptions.Resolution = Get(config, "options/video/Resolution", defaultVideo.Resolution);
            options.videoOptions.Windowed = Get(config, "options/video/Windowed", defaultVideo.Windowed);
            options.videoOptions.TextureQuality = Get(config, "options/video/TextureQuality", defaultVideo.TextureQuality);
            options.videoOptions.AntiAliasing = Get(config, "options/video/AntiAliasing", defaultVideo.AntiAliasing);
            options.videoOptions.ShadingEnabled = Get(config, "options/video/ShadingEnabled", defaultVideo.ShadingEnabled);
            options.audioOptions.ambientSound.Volume = Get(config, "options/audio/ambientSound/Volume", defaultAudio.ambientSound.Volume);
            options.audioOptions.ambientSound.Muted = Get(config, "options/audio/ambientSound/Muted", defaultAudio.ambientSound.Muted);
            options.audioOptions.backgroundSound.Volume = Get(config, "options/audio/backgroundSound/Volume", defaultAudio.backgroundSound.Volume);
            options.audioOptions.backgroundSound.Muted = Get(config, "options/audio/backgroundSound/Muted", defaultAudio.backgroundSound.Muted);
            options.gamePlayOptions.ShowNames = Get(config, "options/gameplay/ShowNames", defaultGame.ShowNames);
            options.gamePlayOptions.ProfanityFilter = Get(config, "options/gameplay/ProfanityFilter", defaultGame.ProfanityFilter);
            options.gamePlayOptions.InterfacePlugin = Get(config, "options/gameplay/InterfacePlugin", defaultGame.InterfacePlugin);
            options.keyBindings.Forward = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Forward", defaultKeys.Forward.ToString()));
            options.keyBindings.Backward = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Backward", defaultKeys.Backward.ToString()));
            options.keyBindings.RotateLeft = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/RotateLeft", defaultKeys.RotateLeft.ToString()));
            options.keyBindings.RotateRight = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/RotateRight", defaultKeys.RotateRight.ToString()));
            //options.keyBindings.FirePrimary = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/FirePrimary", ""));
            //options.keyBindings.FireSecondary = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/FireSecondary", ""));
            options.keyBindings.Menu = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Menu", defaultKeys.Menu.ToString()));
            options.keyBindings.Minimap = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Minimap", defaultKeys.Minimap.ToString()));
            options.keyBindings.Score = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Score", defaultKeys.Score.ToString()));
            options.keyBindings.Camera = (Keys)kc.ConvertFromString(Get(config, "options/keybindings/Camera", defaultKeys.Camera.ToString()));
            options.keyBindings.Pointer = Get(config, "options/keybindings/Pointer", defaultKeys.Pointer);

            if (doCommit)
                WriteOptions(options);

            return options;
        }
开发者ID:summer-of-software,项目名称:vtank,代码行数:66,代码来源:VTankOptions.cs

示例12: GetShortcutKey

        // Retrieve a ShortcutKey ------------------------------------------------------------
        #region SMethod: Keys GetShortcutKey(vGroupID, sItemID, sEnglish, sEnglishShortcutKey) - Workhorse method
        static public Keys GetShortcutKey(
            string[] vGroupID,
            string sItemID,
            string sEnglish,
            string sEnglishShortcutKey)
        {
            // Find (or add) the item, either in vGroupID, or in the Strings hierarchy
            LocItem item = GetLocItem(vGroupID, sItemID, sEnglish);
            Debug.Assert(null != item);

            // Make sure the item has the default English Shortcut Key
            if (string.IsNullOrEmpty(item.ShortcutKey) && !string.IsNullOrEmpty(sEnglishShortcutKey))
                item.ShortcutKey = sEnglishShortcutKey;

            // Otherwise, we want to retrieve the string according to the Primary and
            // Secondary languages, as set up in the settings.
            string sKeys = item.AltShortcutKey;

            // Convert to the Keys type
            try
            {
                KeysConverter converter = new KeysConverter();
                if (!string.IsNullOrEmpty(sKeys))
                {
                    Keys k = (Keys)converter.ConvertFromString(sKeys);
                    return k;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Shortcut key conversion problem: " + e.Message);
            }
            return Keys.None;
        }
开发者ID:neilmayhew,项目名称:pathway,代码行数:36,代码来源:JW_Localization.cs

示例13: listBox1_SelectedIndexChanged

 private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (radioButton1.Checked)
         {
             string s = listBox1.SelectedItem.ToString();
             KeysConverter k = new KeysConverter();
             Object o = k.ConvertFromString(s);
             Keys l = (Keys)o;
             kstartnew = l;
         }
         if (radioButton2.Checked)
         {
             string s = listBox1.SelectedItem.ToString();
             KeysConverter k = new KeysConverter();
             Object o = k.ConvertFromString(s);
             Keys l = (Keys)o;
             kendnew = l;
         }
 }
开发者ID:cugni,项目名称:pds,代码行数:19,代码来源:FrmSelTasti.cs

示例14: RegisterHotKeys

        public void RegisterHotKeys()
        {
            try
            {
                KeysConverter kc = new KeysConverter();

                if (this.closeLastHotKey == null)
                {
                    this.closeLastKeyCombo = (Keys)kc.ConvertFromString(Properties.Settings.Default.KeyboardShortcutCloseLast);
                    this.closeLastHotKey = new HotKeyManager(this.wpr.Handle, this.closeLastKeyCombo);
                    this.closeLastHotKey.Register();
                }

                if (this.closeAllHotKey == null)
                {
                    this.closeAllKeyCombo = (Keys)kc.ConvertFromString(Properties.Settings.Default.KeyboardShortcutCloseAll);
                    this.closeAllHotKey = new HotKeyManager(this.wpr.Handle, this.closeAllKeyCombo);
                    this.closeAllHotKey.Register();
                }
            }
            catch
            {
            }
        }
开发者ID:iwaim,项目名称:growl-for-windows,代码行数:24,代码来源:Program.cs

示例15: PopulateContextMenu

        /// <summary>Populate the context menu from the descriptions passed in.</summary>
        /// <param name="menuDescriptions">Menu descriptions for each menu item.</param>
        public void PopulateContextMenu(List<MenuDescriptionArgs> menuDescriptions)
        {
            PopupMenu.Font = this.Font;
            PopupMenu.Items.Clear();
            foreach (MenuDescriptionArgs Description in menuDescriptions)
            {
                Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream(Description.ResourceNameForImage);
                Bitmap Icon = null;
                if (s != null)
                    Icon = new Bitmap(s);

                ToolStripMenuItem Button = PopupMenu.Items.Add(Description.Name, Icon, Description.OnClick) as ToolStripMenuItem;
                Button.TextImageRelation = TextImageRelation.ImageBeforeText;
                Button.Checked = Description.Checked;
                if (Description.ShortcutKey != null)
                {
                    KeysConverter kc = new KeysConverter();
                    Button.ShortcutKeys = (Keys)kc.ConvertFromString(Description.ShortcutKey);
                }
                Button.Enabled = Description.Enabled;
            }
        }
开发者ID:hol353,项目名称:ApsimX,代码行数:24,代码来源:ExplorerView.cs


注:本文中的System.Windows.Forms.KeysConverter.ConvertFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。