Select the form:
Set the KeyPreview property of the form to true so that keyboard messages are received by the form before they reach any controls on the form.
Create a KeyPress event (detects keys down combined with any modifier key – i.e. no event for pressing CTRL and a modified key value for CTRL + ‘y’
Or create a KeyDown event (detects every key down including modifier keys and gives individual key value)
Example Handler
//***********************************
//***********************************
//********** FORM KEY DOWN **********
//***********************************
//***********************************
private: System::Void frmMain_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e)
{
try
{
//MessageBox::Show("Form.KeyPress: '" + e->KeyValue.ToString() + "' pressed.");
if ((Control::ModifierKeys == Keys::Control) && (e->KeyValue == 'L')) //Key values are for CAPS version of letters
{
//----- CTRL+L PRESSED -----
textBox1->Text = "A";
}
}
catch (Exception ^)
{
}
}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.