Create input for custom keyboard shortcuts

I am using Visual Studio 2010 to create a visual C # application, and I want to include some parameters in my application settings for customizing keyboard shortcuts using some kind of text box input. I understand how to write keyboard input and how to save it in the settings of the user application, but I can not find any input controls that have this functionality.

those. something like that:

enter image description here

But using Windows forms (Note: above from Divvy for OS X from the app store).

Is there any built-in functionality for this? Are there any good libraries or user inputs that I could use?

Otherwise, any suggestions on how to implement something like this?

Decision:

Using Bas B answer and some other logic:

private void fShortcut_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Back) { Keys modifierKeys = e.Modifiers; Keys pressedKey = e.KeyData ^ modifierKeys; //remove modifier keys if (modifierKeys != Keys.None && pressedKey != Keys.None) { //do stuff with pressed and modifier keys var converter = new KeysConverter(); fShortcut.Text = converter.ConvertToString(e.KeyData); //At this point, we know a one or more modifiers and another key were pressed //modifierKeys contains the modifiers //pressedKey contains the other pressed key //Do stuff with results here } } else { e.Handled = false; e.SuppressKeyPress = true; fShortcut.Text = ""; } } 

The above method indicates when a valid combination of shortcuts is entered, checking whether both modifier keys and the other key are pressed.

+4
source share
1 answer

The user can enter the preferred shortcut in the TextBox, and then handle the KeyDown event, for example:

  private void textBox1_KeyDown(object sender, KeyEventArgs e) { Keys modifierKeys = e.Modifiers; Keys pressedKey = e.KeyData ^ modifierKeys; //remove modifier keys //do stuff with pressed and modifier keys var converter = new KeysConverter(); textBox1.Text = converter.ConvertToString(e.KeyData); } 

Edit: Updated to include Stecya's answer.

+4
source

Source: https://habr.com/ru/post/1383890/


All Articles