Could you please tell me how to use the "globalmousekeyhook" library (https://github.com/gmamaladze/globalmousekeyhook/blob/vNext/keycomb.md) to write keyboard shortcuts Not to the whole application, but to a specific form? To avoid checking the form for activity, every time (Form.ActiveForm == this). P.S. If you do not do these checks, the keyboard shortcuts, will be triggered simultaneously in all created forms.
private void Form1_Load(object sender, EventArgs e) {
Action ex1 = () => { if (Form.ActiveForm == this) Dop.ChangeBackColor(this, Color.Black); };
Action ex2 = () => { if (Form.ActiveForm == this) Dop.ChangeBackColor(this, Color.Green); };
// Install listener App [Combinations]
Hook.AppEvents().OnCombination(new Dictionary<Combination, Action> {
{ Combination.FromString("Control + S"), ex1 },
{ Combination.FromString("Control + D"), ex2 }
});
}
Solution for AppEvents
Solution for GlobalEvents (If you have only 1 form in your application)
Activate GlobalEvents in FormName_Load
Deactivate GlobalEvents in FormName_Closed (Not obligatory: closing the main form will close the entire application
Solution for GlobalEvents (If you have more than 1 form in your application)
Hide the desired form using Hide(), open another one. According to the book (http://it-kniga.narod.ru/5-7502-0222-4/02020903.html), method Hide() is analogous to Visible = false;
Create the FormName_VisibleChanged event. Write the code in all the necessary forms (example: FormMain, Form1, FormName...). This method allows you to activate GlobalEvents for each individual form instead of all running (hidden) forms.