/// <summary> /// This processes messages, so a console application can use message based functionality, like low level keyboard events. /// The loop is very basic, /// </summary> /// <param name="handler">An optional function to process the message, return false to stop handling</param> /// <param name="hWnd">IntPtr with the window handle to get the messages for</param> /// <param name="wMsgFilterMin">The integer value of the lowest message value to be retrieved. Use WM_KEYFIRST (0x0100) to specify the first keyboard message or WM_MOUSEFIRST (0x0200) to specify the first mouse message.</param> /// <param name="wMsgFilterMax">The integer value of the highest message value to be retrieved. Use WM_KEYLAST to specify the last keyboard message or WM_MOUSELAST to specify the last mouse message.</param> public static void ProcessMessages(MessageProc handler = null, IntPtr hWnd = default, uint?wMsgFilterMin = null, uint?wMsgFilterMax = null) { do { var hasMessage = GetMessage(out var msg, hWnd, wMsgFilterMin ?? 0, wMsgFilterMax ?? 0); if (hasMessage == -1) { // Error! break; } if (hasMessage == 0) { // Error! break; } // Typical logic for processing the messages TranslateMessage(ref msg); DispatchMessage(ref msg); if (handler != null && !handler(ref msg)) { break; } } while (true); }
public bool Hook(Process process, bool useCallback = true) { if (process == null) { return(false); } if (_hookID != IntPtr.Zero) { Unhook(); } referenceProcess = process; mainWindowHandle = process.MainWindowHandle; if (useCallback) { proc = new MessageProc(HookCallback); _hookID = SetWindowsHookEx(WH_KEYBOARD_LL, proc, IntPtr.Zero, 0); if (_hookID != IntPtr.Zero) { return(true); } else { return(false); } } return(true); }
public void UnregisterProc(int msg, MessageProc proc) { if (procs.ContainsKey(msg)) { procs[msg] -= proc; } }
//------------------------------------------------- // CNodeManager - Constructor // // The constructor initializes our node store with the // ability to initially store 1 node //------------------------------------------------- static internal void Init() { m_nNodes = new CNode[1]; NullOutArray(ref m_nNodes); m_iCookieCount = 0; m_iNumSlots = 1; m_fDisplayedTwice = false; // We create a hidden window to allow us to communicate with modeless // dialogs and other things which run in a seperate thread. // I could do all this using Windows.Forms classes, but I don't want to // take the hit loading that module to start IntPtr hInst = (IntPtr)Marshal.GetHINSTANCE((Assembly.GetExecutingAssembly().GetLoadedModules())[0]); if (m_dlgMessageProc == null) { m_dlgMessageProc = new MessageProc(NodeManagerMessageProc); } WNDCLASS wc = new WNDCLASS(); wc.lpfnWndProc = m_dlgMessageProc; wc.hInstance = hInst; wc.lpszClassName = "NodeManagerMessagePump"; RegisterClass(ref wc); m_hMessageWnd = CreateWindowEx(0, "NodeManagerMessagePump", null, 0, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, hInst, IntPtr.Zero); }// Init
public void RegisterProc(int msg, MessageProc proc) { if (procs.ContainsKey(msg)) { procs[msg] += proc; } else { procs[msg] = proc; } }
// ユーティリティ --------------------------------------------- // メンバーは、_Action3 の配列に保管してもいいな ああ、でも数が増えるとあれだからいまいちか /// <summary> /// メンバーへのデリゲート配送システム。 /// </summary> /// <param name="proc">配送されるデリゲート</param> public void sendProcToAllMembers(MessageProc proc) { for (var i = tf.childCount; i-- > 0;) { var iAct = tf.GetChild(i).GetComponent <_Action3>(); if (iAct != null) { proc(iAct); } } }
private static extern IntPtr SetWindowsHookEx(int idHook, MessageProc lpfn, IntPtr hMod, uint dwThreadId);
// Token: 0x0600526B RID: 21099 RVA: 0x00186F04 File Offset: 0x00185104 private void ProcessMessages(MessageProc proc = null) { while (!this.m_isBlockProcessMsg) { KeyValuePair <int, object> messagePair = this.m_connect.GetMessagePair(); if (messagePair.Value == null) { break; } int key = messagePair.Key; int state = this.m_csm.State; if (proc != null && proc(key, messagePair.Value)) { if (state != this.m_csm.State) { return; } } else { switch (key) { case 9001: this.m_csm.SetStateCheck(2, -1, false); this.m_clientEventHandler.OnConnected(); return; case 9002: this.m_csm.SetStateCheck(4, -1, false); this.m_clientEventHandler.OnDisconnected(); return; case 9003: this.m_csm.SetStateCheck(4, -1, false); this.m_clientEventHandler.OnError(key, "connection disconnected"); return; case 9004: { this.m_csm.SetStateCheck(4, -1, false); CCMSGConnectionSendFailure ccmsgconnectionSendFailure = messagePair.Value as CCMSGConnectionSendFailure; this.m_clientEventHandler.OnError(key, ccmsgconnectionSendFailure.ExceptionInfo); if (this.m_connect.State == ConnectionState.Connecting || this.m_connect.State == ConnectionState.Established) { this.Close(); } return; } case 9005: { this.m_csm.SetStateCheck(4, -1, false); CCMSGConnectionRecvFailure ccmsgconnectionRecvFailure = messagePair.Value as CCMSGConnectionRecvFailure; this.m_clientEventHandler.OnError(key, ccmsgconnectionRecvFailure.ExceptionInfo); if (this.m_connect.State == ConnectionState.Connecting || this.m_connect.State == ConnectionState.Established) { this.Close(); } return; } default: this.m_clientEventHandler.OnMessage(messagePair.Value, key); break; } } } }