本文整理汇总了C#中System.Windows.Forms.KeysConverter.ConvertFrom方法的典型用法代码示例。如果您正苦于以下问题:C# KeysConverter.ConvertFrom方法的具体用法?C# KeysConverter.ConvertFrom怎么用?C# KeysConverter.ConvertFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.KeysConverter
的用法示例。
在下文中一共展示了KeysConverter.ConvertFrom方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: ParseShortcut
/// <summary>Parses a shortcut string like 'Control + Alt + Shift + V' and returns the key and modifiers.
/// </summary>
/// <param name="text">The shortcut string to parse.</param>
/// <returns>The Modifier in the lower bound and the key in the upper bound.</returns>
public static object[] ParseShortcut(string text)
{
bool HasAlt = false; bool HasControl = false; bool HasShift = false; bool HasWin = false;
Modifiers Modifier = Modifiers.None; //Variable to contain modifier.
Keys key = 0; //The key to register.
int current = 0;
string[] result;
string[] separators = new string[] { " + " };
result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
//Iterate through the keys and find the modifier.
foreach (string entry in result)
{
//Find the Control Key.
if (entry.Trim() == Keys.Control.ToString())
{
HasControl = true;
}
//Find the Alt key.
if (entry.Trim() == Keys.Alt.ToString())
{
HasAlt = true;
}
//Find the Shift key.
if (entry.Trim() == Keys.Shift.ToString())
{
HasShift = true;
}
//Find the Window key.
if (entry.Trim() == Keys.LWin.ToString() && current != result.Length - 1)
{
HasWin = true;
}
current++;
}
if (HasControl) { Modifier |= Modifiers.Control; }
if (HasAlt) { Modifier |= Modifiers.Alt; }
if (HasShift) { Modifier |= Modifiers.Shift; }
if (HasWin) { Modifier |= Modifiers.Win; }
KeysConverter keyconverter = new KeysConverter();
key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));
return new object[] { Modifier, key };
}
示例3: GetKeysFromString
private static Keys GetKeysFromString(string keys)
{
var converter = new KeysConverter();
var keySequence = converter.ConvertFrom(null, CultureInfo.CurrentCulture, keys);
if (keySequence != null)
{
return (Keys)keySequence;
}
return Keys.None;
}
示例4: GenerateSubMenuItem
private void GenerateSubMenuItem(PluginLoader pluginLoader, ToolStripMenuItem parentMenuItem, Menu menu)
{
foreach(Menu mm in menu.SubMenus)
{
ToolStripMenuItem menuItem = new ToolStripMenuItem(mm.Name);
// add image menu item
if (mm.Image != null)
menuItem.Image = Image.FromStream(new MemoryStream(mm.Image));
// add shorcut menu item
menuItem.ShowShortcutKeys = true;
if (mm.ShortcutKey != null)
{
menuItem.ShortcutKeyDisplayString = mm.ShortcutKey;
KeysConverter cvt = new KeysConverter();
menuItem.ShortcutKeys = (Keys)cvt.ConvertFrom(mm.ShortcutKey);
}
// add handler click menu item
if (mm.Type == Convert.ToInt32(MenuType.COMMAND))
{
// asociate plugin instance assembly
mm.Assembly = pluginLoader.LoadAndRun(mm.AssemblyName, mm.AssemblyVersion, mm.Image);
menuItem.Tag = mm;
menuItem.Click += new EventHandler(PluginHandler_Click);
}
parentMenuItem.DropDownItems.Add(menuItem);
if (mm.Type == Convert.ToInt32(MenuType.MENU))
GenerateSubMenuItem(pluginLoader, menuItem, mm);
}
}
示例5: UpdateCustomShortcut
void UpdateCustomShortcut(string text)
{
LogEvents("Attempting to update custom shortcut to: " + text);
//Will help determine if the shortcut has any modifier.
bool HasAlt = false; bool HasControl = false; bool HasShift = false;
Modifiers Modifier = Modifiers.None; //Variable to contain modifier.
Keys key = 0; //The key to register.
string[] result;
string[] separators = new string[] { " + " };
result = text.Split(separators, StringSplitOptions.RemoveEmptyEntries);
//Iterate through the keys and find the modifier.
foreach (string entry in result)
{
//Find the Control Key.
if (entry.Trim() == Keys.Control.ToString())
{
HasControl = true;
}
//Find the Alt key.
if (entry.Trim() == Keys.Alt.ToString())
{
HasAlt = true;
}
//Find the Shift key.
if (entry.Trim() == Keys.Shift.ToString())
{
HasShift = true;
}
}
if (HasControl) { Modifier |= Modifiers.Control; }
if (HasAlt) { Modifier |= Modifiers.Alt; }
if (HasShift) { Modifier |= Modifiers.Shift; }
//Get the last key in the shortcut
KeysConverter keyconverter = new KeysConverter();
key = (Keys)keyconverter.ConvertFrom(result.GetValue(result.Length - 1));
ghkCustom.Enabled = chkCustomEnabled.Checked;
ghkCustom.Key = key;
ghkCustom.Modifier = Modifier;
LogEvents(string.Format("Custom shortcut updated. \n Key:{0}, Modifier:{1}", ghkCustom.Key, ghkCustom.Modifier));
}