Hack Forums
[.NET] Need a little help with a user defined hotkey - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Need a little help with a user defined hotkey (/showthread.php?tid=5099545)



Need a little help with a user defined hotkey - Lone - Dec 18, 2015

Trying to create a part of my program to allow users to keybind whatever button they would like and might be going at it the wrong way. Basically what I have is textbox that will allow the user to enter a number for the hotkey lets say "118" which is F7. I would like it to go like it to replace Keys.F7 to whatever they have.

Code
Select Case e.KeyCode
            Case Keys.F7 // I have tried making this an integer that took a value but //it did not work
                MessageBox.Show("Testing")
            Case Keys.F8
                MessageBox.Show("Testing2")

        End Select



* - BahNahNah - Dec 18, 2015

Two options.

Make a new form that is something like this:
Spoiler (Click to View)

Then use it like:
Code
using (demoForm hkForm = new demoForm())
{
    if(hkForm.ShowDialog() == DialogResult.OK)
    {
        Keys selectedKey = hkForm.SelectedKey;
    }
}

Spoiler (Click to View)

Or use reflection:
Code
Keys k = (Keys)typeof(Keys).GetField(comboBox.Text).GetValue(null);



* - Odus - Dec 18, 2015

How about a Dictionary(Of Keys, String) to hold it? Prevents you having to account for each key individually with a huge switch.