本文整理汇总了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);
}
}
示例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);
}
示例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();
};
}
示例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;
}
}
示例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();
}
});
}
示例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();
}
示例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;
}
示例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));
}
示例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));
}
}
示例10: Print
public static void Print(string text) {
KeysConverter kv = new KeysConverter();
kv.ConvertFromString("abc");
}
示例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;
}
示例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;
}
示例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;
}
}
示例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
{
}
}
示例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;
}
}