使用库“globalmousekeyhook”时,出现了两个问题:
问题 #1:从单独的类调用全局事件时不起作用
- If place the code to activate Global Events in a separate class (in a method) and then call it from the main form (FormName_Load) - then Global Events stops working (nothing happens).
- If use the code to activate Global Events in the main form (FormName_Load), without wrappers - everything works.
问题 #2:应用事件工作异常
分别以两种形式编写了用于更改背景的代码:
// Install listener App [Combinations]
Hook.AppEvents().OnCombination(new Dictionary<Combination, Action> {
{ Combination.FromString("Control + S"), () => { this.BackColor= Color.Black; }
}});
启动表单 (Form1.Hide(); Form2.Show();) 后,当您激活组合键 (Ctrl + S) - 两种表单的颜色都发生了变化(仅在活动表单中需要颜色更改)。