Enabling Hotkey Selection For Controls
How to enable hotkey-selection for default Windows Controls and User Controls
Firstly off, instantiate a new HotkeySelector
instance:
var hks = new HotkeySelector();
To enable any control for hotkey selection, use the Enable()
method:
hks.Enable(textBox1);
When enabling a control, you can set the default hotkey to be displayed:
// We'll use the hotkey we defined in our previous examples.
hks.Enable(textBox1, hotkey1);
...or we can create a new hotkey then set it as the default hotkey for a selector control:
// Create a new hotkey.
Hotkey hotkey2 = new Hotkey(Keys.Control | Keys.Shift, Keys.J);
// ...then set the default hotkey for a selector.
hks.Enable(textBox1, hotkey1);
To set a hotkey without necessarily enabling the control for hotkey selection, use the Set()
method:
hks.Set(textbox1, hotkey1);
HotkeySelector
also helps detect whether a hotkey or hotkey-combination is a Windows-registered hotkey or not and therefore unavailable for use - e.g.Control
+Alt
+Delete
. So no need to account for such scenarios. 😉
Let's move a little further...
Last updated
Was this helpful?