public KeyHook(Form form) { this.form = form; keyDown.Add(Keys.LWin, delegate { win_pushed = true; return(false); }); keyUp.Add(Keys.LWin, delegate { win_pushed = false; return(false); } ); keyUp.Add(Keys.Left, delegate { if (form.Visible) { LeftArrowEvent?.Invoke(); return(false); } return(true); }); keyUp.Add(Keys.Right, delegate { if (form.Visible) { RightArrowEvent?.Invoke(); return(false); } return(true); }); keyUp.Add(Keys.Enter, delegate { if (form.Visible) { EnterClickEvent?.Invoke(); return(false); } return(true); }); keyUp.Add(Keys.Escape, delegate { if (form.Visible) { OpenCloseEvent?.Invoke(); return(false); } return(true); }); startApps.Add(Keys.D, delegate { OpenCloseEvent?.Invoke(); }); startApps.Add(Keys.E, delegate { Process.Start("explorer"); }); startApps.Add(Keys.I, delegate { Process.Start("ms-settings:"); }); startApps.Add(Keys.L, delegate { Process.Start("rundll32.exe user32.dll,LockWorkStation"); }); startApps.Add(Keys.R, delegate { Shell32.Shell shell = new Shell32.Shell(); shell.FileRun(); }); startApps.Add(Keys.D0, delegate { ShutdownClickEvent?.Invoke(); }); hookDelegate = HookCallback; using (Process curProcess = Process.GetCurrentProcess()) { using (ProcessModule curModule = curProcess.MainModule) { _hookID = SetWindowsHookEx(WH_KEYBOARD_LL, hookDelegate, GetModuleHandle(curModule.ModuleName), 0); } } }
public void Invoke(OpenCloseEvent openCloseEvent) { _eventsManager.Invoke(openCloseEvent); }
public void On(OpenCloseEvent openCloseEvent, UnityAction call) { _eventsManager.On(openCloseEvent, call); }
public void Remove(OpenCloseEvent openCloseEvent, UnityAction call) { _eventsManager.Remove(openCloseEvent, call); }
/// <summary> /// Open or close this behavior's parent, via the specified actor. /// </summary> /// <param name="actor">The actor doing the opening or closing.</param> /// <param name="verb">Whether this is an "open" or "close" action.</param> /// <param name="newOpenedState">The new IsOpen state to be set, if the request is not cancelled.</param> private void OpenOrClose(Thing actor, string verb, bool newOpenedState) { // If we're already in the desired opened/closed state, we're already done with state changes. if (newOpenedState == this.IsOpen) { // @@@ TODO: Message to the actor that it is already open/closed. return; } // Prepare the Close/Open game event for sending as a request, and if not cancelled, again as an event. var csb = new ContextualStringBuilder(actor, this.Parent); csb.Append(@"You " + verb + " $TargetThing.Name.", ContextualStringUsage.OnlyWhenBeingPassedToOriginator); csb.Append(@"$ActiveThing.Name " + verb + "s you.", ContextualStringUsage.OnlyWhenBeingPassedToReceiver); csb.Append(@"$ActiveThing.Name " + verb + "s $TargetThing.Name.", ContextualStringUsage.WhenNotBeingPassedToReceiverOrOriginator); var message = new SensoryMessage(SensoryType.Sight, 100, csb); var e = new OpenCloseEvent(this.Parent, newOpenedState, actor, message); // Broadcast the Open or Close Request and carry on if nothing cancelled it. // Use a temporary ref to our own parent to avoid race conditions like sudden parent removal. var thisThing = this.Parent; if (thisThing != null) { // Broadcast from the parents of the openable/closable thing (IE the rooms an openable exit is attached to). thisThing.Eventing.OnMiscellaneousRequest(e, EventScope.ParentsDown); if (!e.IsCancelled) { // Open or Close the thing. this.IsOpen = newOpenedState; // Broadcast the Open or Close event. thisThing.Eventing.OnMiscellaneousEvent(e, EventScope.ParentsDown); } } }