當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。