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


C# Forms.KeysConverter类代码示例

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


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

示例1: fShortcut_KeyDown

        private void fShortcut_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode != Keys.Back)
            {
                Keys modifierKeys = e.Modifiers;
                Keys pressedKey = e.KeyData ^ modifierKeys; //remove modifier keys

                if (modifierKeys != Keys.None && pressedKey != Keys.None && pressedKey != Keys.Menu && pressedKey != Keys.ControlKey)
                {
                    //do stuff with pressed and modifier keys
                    var converter = new KeysConverter();
                    fShortcut.Text = converter.ConvertToString(e.KeyData);
                    //At this point, we know a one or more modifiers and another key were pressed
                    //modifierKeys contains the modifiers
                    //pressedKey contains the other pressed key
                    //mainform.UnregisterHooks();
                   // mainform.RegisterFileHook(modifierKeys, pressedKey);
                    Properties.Settings.Default.fShortcut = converter.ConvertToInvariantString(e.KeyData);
                }
            }
            else
            {
                e.Handled = false;
                e.SuppressKeyPress = true;

                fShortcut.Text = "";
            }
        }
开发者ID:WilHall,项目名称:synchy-win,代码行数:28,代码来源:Preferences.cs

示例2: ReadKeyCode

        public static string ReadKeyCode(int vkCode)
        {
            var key = (Keys)vkCode;
            KeysConverter converter = new KeysConverter();
            return converter.ConvertToString(key);

            //char ch = ' ';

            //int virtualKey = KeyInterop.VirtualKeyFromKey(key);
            //byte[] keyboardState = new byte[256];
            //GetKeyboardState(keyboardState);

            //uint scanCode = MapVirtualKey((uint)virtualKey, MapType.MAPVK_VK_TO_VSC);
            //StringBuilder stringBuilder = new StringBuilder(2);

            //int result = ToUnicode((uint)virtualKey, scanCode, keyboardState, stringBuilder, stringBuilder.Capacity, 0);
            //switch (result)
            //{
            //    case -1:
            //        break;
            //    case 0:
            //        break;
            //    case 1:
            //        {
            //            ch = stringBuilder[0];
            //            break;
            //        }
            //    default:
            //        {
            //            ch = stringBuilder[0];
            //            break;
            //        }
            //}
            //return ch.ToString();
        }
开发者ID:borigas,项目名称:EventTracker,代码行数:35,代码来源:KeyHelpers.cs

示例3: USBScannerListener

 public USBScannerListener(Form form)
 {
     form.KeyUp += scannerKeyUp;
     this.words = new List<string>();
     this.currentWord = string.Empty;
     this.keyConverter = new KeysConverter();
 }
开发者ID:Rickedb,项目名称:USBScanner,代码行数:7,代码来源:USBScannerListener.cs

示例4: 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

示例5: SendRequestInternal

        protected override void SendRequestInternal(string request)
        {
            string[] args = StringUtils.ToStringArray(request, ',');

            string keyCode = "", repeat = "", command = "", windowName = "", remoteName = "";

            int i = 0;
            if (args.Length > i)
                keyCode = args[i++];
            if (args.Length > i)
                repeat = args[i++];
            if (args.Length > i)
                command = args[i++];
            if (args.Length > i)
                windowName = args[i++];
            if (args.Length > i)
                remoteName = args[i++];

            IntPtr hWnd = User32.FindWindow(windowName, null);
            if (hWnd != IntPtr.Zero)
            {
                KeysConverter kc = new KeysConverter();
                Keys k = (Keys)kc.ConvertFromInvariantString(command);
                KeyEventArgs kea = new KeyEventArgs(k);

                // Key down
                int msg = (int)Messages.WM_KEYDOWN;
                User32.PostMessage(hWnd, msg, kea.KeyValue, 0);
            }
        }
开发者ID:rraguso,项目名称:protone-suite,代码行数:30,代码来源:HotkeyOutputPin.cs

示例6: set_hotkey

        public void set_hotkey(string hotkey_string)
        {
            var cvt = new KeysConverter();
            var key = (Keys)cvt.ConvertFrom(hotkey_string);

            ModifierKeys mk = SkipDonation.ModifierKeys.None;

            if (key.HasFlag(Keys.Control))
            {
                mk |= SkipDonation.ModifierKeys.Control;
                key = key & (~Keys.Control);
            }

            if (key.HasFlag(Keys.Alt))
            {
                mk |= SkipDonation.ModifierKeys.Alt;
                key = key & (~Keys.Alt);
            }

            if (key.HasFlag(Keys.Shift))
            {
                mk |= SkipDonation.ModifierKeys.Shift;
                key = key & (~Keys.Shift);
            }

            hook.RegisterHotKey(mk, key);
            lbl_hotkey.Text = hotkey_string;
        }
开发者ID:pajlada,项目名称:SkipDonation,代码行数:28,代码来源:MainForm.cs

示例7: textBox1_KeyDown

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            Keys modifierKeys = e.Modifiers;

            Keys pressedKey = e.KeyData ^ modifierKeys; //remove modifier keys

            //do stuff with pressed and modifier keys
            var converter = new KeysConverter();
            //textBox1.Text = converter.ConvertToString(e.KeyData);
        }
开发者ID:riyadparvez,项目名称:prank-sharp,代码行数:10,代码来源:SettingsForm.cs

示例8: CanConvertTo

		public void CanConvertTo ()
		{
			KeysConverter c = new KeysConverter ();

			Assert.AreEqual (true, c.CanConvertTo (null, typeof (string)), "A1");
			Assert.AreEqual (false, c.CanConvertTo (null, typeof (int)), "A2");
			Assert.AreEqual (false, c.CanConvertTo (null, typeof (float)), "A3");
			Assert.AreEqual (false, c.CanConvertTo (null, typeof (object)), "A4");
			Assert.AreEqual (false, c.CanConvertTo (null, typeof (Enum)), "A5");
			Assert.AreEqual (true, c.CanConvertTo (null, typeof (Enum [])), "A6");
		}
开发者ID:Profit0004,项目名称:mono,代码行数:11,代码来源:KeysConverterTest.cs

示例9: listView1_KeyDown

        private void listView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (listView1.SelectedIndices.Count > 0)
            {
                KeysConverter kc = new KeysConverter();

                ListViewItem lvi = listView1.Items[listView1.SelectedIndices[0]];
                lvi.SubItems[3].Text = kc.ConvertToString(e.KeyData);
                lvi.SubItems[3].Tag = e.KeyData;
                e.Handled = true;
            }
        }
开发者ID:gahadzikwa,项目名称:GAPP,代码行数:12,代码来源:SettingsPanel.cs

示例10: 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

示例11: 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

示例12: 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

示例13: SetDestPathWithOverwriteConfirm

 public void SetDestPathWithOverwriteConfirm(string path)
 {
     string keyStr = new KeysConverter().ConvertToString((this.LinkedKey & ~Keys.Shift));
     if ((this.LinkedKey & Keys.Shift) == Keys.Shift)
         keyStr = "Shift + " + keyStr;
     var dr = MessageBox.Show(
         "キー " + LinkedKey.ToString() + "にはすでに設定されているパスがあります。" + Environment.NewLine +
         "すでにこのキーへ振り分けた画像の振り分け先も変更しますか?" + Environment.NewLine +
         "(キャンセルを押すと上書きをしません)",
         "キー設定の上書き",
         MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
     if (dr == DialogResult.Cancel)
         return;
     else
         this.SetDestPath(path, dr == DialogResult.Yes);
 }
开发者ID:karno,项目名称:Typict,代码行数:16,代码来源:Destination.cs

示例14: 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

示例15: ShortCutDropDownLoop

 private void ShortCutDropDownLoop(ToolStripMenuItem ts)
 {
     for (int i = 0; i < ts.DropDownItems.Count; i++)
     {
         if ((ts.DropDownItems[i].Tag != null) && (ts.DropDownItems[i].Tag.ToString() != ""))
         {
             ToolStripMenuItem item = (ToolStripMenuItem) ts.DropDownItems[i];
             string text = this.ShortCutAdd(this.TagName(item.Tag.ToString()));
             KeysConverter converter = new KeysConverter();
             item.ShortcutKeys = (Keys) converter.ConvertFromInvariantString(text);
         }
         else if ((ts.DropDownItems[i].GetType() == typeof(ToolStripMenuItem)) && (((ToolStripMenuItem) ts.DropDownItems[i]).DropDownItems.Count > 0))
         {
             this.ShortCutDropDownLoop((ToolStripMenuItem) ts.DropDownItems[i]);
         }
     }
 }
开发者ID:huamanhtuyen,项目名称:VNACCS,代码行数:17,代码来源:UserKeySet.cs


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