//Methods //Global message listener private IntPtr MsgListener(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { try { const int WM_HOTKEY = 0x0312; switch (msg) { case WM_HOTKEY: var l = lParam.ToInt32(); var w = wParam.ToInt32(); #if DEBUGLOG short code = 0; string command = "null"; #endif foreach (var key in WinWrapper.HotKeys) { int shortcode = WinWrapper.KeyDict[key.Key]; int longcode = WinWrapper.VirtualKeyCodes[shortcode] + (key.StringModifier == null ? 0 : WinWrapper.KeyDict[key.StringModifier]); if (l == shortcode || w == shortcode || l == longcode || w == longcode) { switch (key.KeyStatus) { case HotKeyStatus.AddAction: foreach (var template in ViewModel.viewModel.ActionTemplates) { if (template.HotKey == key) { var pos = System.Windows.Forms.Cursor.Position; ViewModel.viewModel.SelectedMacro?.CommandAddAction.Execute(new ActionMeta((uint)pos.X, (uint)pos.Y, template, ScreenCapture.CaptureFromScreen(64, 64, pos.X, pos.Y))); #if DEBUGLOG command = "CommandAddAction"; code = 1; #endif } } break; case HotKeyStatus.ExecuteScenario: foreach (var scen in ViewModel.viewModel.Scenarios) { if (scen.HotKey.Key == key.Key) { ViewModel.viewModel.SelectedScenario = scen; ViewModel.viewModel.CommandExecuteScenarioAsync.Execute(null); #if DEBUGLOG command = "CommandExecuteScenarioAsync"; code = 1; #endif } } break; default: break; } } } #if DEBUGLOG Logger.GetLogger().WriteToLog($"MsgListener: MessageReceived: Msg{{{WM_HOTKEY}}}, l{{{l}}}, w{{{w}}} : Command{{{command}}}, Code{{{code}}}"); #endif break; default: break; } } catch (Exception ex) { Logger.GetLogger().CatchException("MainWindow", "MsgListener", ex.Message); throw; } return(IntPtr.Zero); }