public
Authored by avatar Jayson De Los Santos

WPF C# - Convert String to Input.Key

If you are trying to create a dynamic hotkeys, this code might be applicable to you

image image image

Edited
key_converter.cs 637 bytes
    private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if(e.Key==Key.Escape)
            {
                this.Close();
            }
            else
            {
                foreach(var inquiry in balance_inquiries)
                {
                    KeyConverter k = new KeyConverter();
                    Key mykey = (Key)k.ConvertFromString(inquiry.hotkey);
                    if (e.Key == mykey)
                    {
                       Globals.MsgboxOk(this, "You select " + inquiry.hotkey + " - " + inquiry.name);
                    }
                }
            }
        }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment