private static bool OnMouseInputReceived(Win32.WM wParam, Win32.WindowHook.MSLLHOOKSTRUCT hookStruct) { if (Win32.WindowHook.LLMHF.INJECTED == (hookStruct.flags & Win32.WindowHook.LLMHF.INJECTED)) { return(false); } MouseInput mouseInputEventArgs = MouseInput.CreateFrom((Win32.WM)wParam, hookStruct); mouseInputEventArgs.WM = wParam; if (Performance.IsPerformanceEnabled) { MouseInputPerformance.Count(Convert.ToInt64(mouseInputEventArgs.Time)); } try { if (MouseInputReceived != null) { MouseInputReceived(mouseInputEventArgs); return(mouseInputEventArgs.Handled); } } catch (Exception ex) { Debug.WriteLine(ex.Message); Debug.WriteLine(ex.StackTrace); } return(false); }
public void AddBubbleEvent(Func <BubbleEventArgs, bool> handleEvent, Win32.WM message) { messages.Add((int)message, new BubbleEvent { Message = message, HandleEvent = handleEvent }); }
public static MouseInput CreateFrom(Win32.WM wm, Mubox.Win32.WindowHook.MSLLHOOKSTRUCT hookStruct) { MouseInput e = new MouseInput(); e.WM = wm; e.Point = new System.Windows.Point(hookStruct.pt.X, hookStruct.pt.Y); e.MouseData = hookStruct.mouseData; e.Time = hookStruct.time; return(e); }
public static KeyboardInput CreateFrom(Win32.WM wParam, Mubox.Win32.WindowHook.KBDLLHOOKSTRUCT hookStruct) { KeyboardInput e = new KeyboardInput(); e.VK = hookStruct.vkCode; e.Scan = hookStruct.scanCode; e.Flags = hookStruct.flags; e.Time = hookStruct.time; e.WM = wParam; return(e); }
private static bool OnKeyboardInputReceived(Win32.WM wParam, Win32.WindowHook.KBDLLHOOKSTRUCT hookStruct) { // fix for 'key repeat' windows feature if (pressedKeys.Contains((byte)(hookStruct.vkCode & 0xFF))) { return(false); } // and ignore "global desktop keys" Mubox.Configuration.KeySetting globalKeySetting = null; if (Mubox.Configuration.MuboxConfigSection.Default.Keys.TryGetKeySetting((Win32.VK)hookStruct.vkCode, out globalKeySetting) && (globalKeySetting.SendToDesktop)) { return(false); } // filter repeated keys, we don't rebroadcast these if (IsRepeatKey(hookStruct) && Mubox.Configuration.MuboxConfigSection.Default.IsCaptureEnabled && !Mubox.Configuration.MuboxConfigSection.Default.DisableRepeatKeyFiltering) { return(true); } // count if (Performance.IsPerformanceEnabled) { KeyboardInputPerformance.Count(Convert.ToInt64(hookStruct.time)); } // handle high-level if (KeyboardInputReceived != null) { KeyboardInput keyboardInputEventArgs = KeyboardInput.CreateFrom(wParam, hookStruct); { Mubox.Configuration.KeySetting keySetting = globalKeySetting; if (Mubox.Configuration.MuboxConfigSection.Default.Teams.ActiveTeam != null) { Mubox.Configuration.ClientSettings activeClient = Mubox.Configuration.MuboxConfigSection.Default.Teams.ActiveTeam.ActiveClient; if (activeClient != null) { activeClient.Keys.TryGetKeySetting((Win32.VK)keyboardInputEventArgs.VK, out keySetting); } if (keySetting != null) { keyboardInputEventArgs.VK = (uint)keySetting.OutputKey; keyboardInputEventArgs.CAS = keySetting.OutputModifiers; } } } OnKeyboardInputReceivedInternal(keyboardInputEventArgs); return(keyboardInputEventArgs.Handled); } return(false); }
private void OnMouseEvent_Action(int pointX, int pointY, int lPointX, int lPointY, Win32.WM wm, uint mouseData, bool isButtonUpEvent) { uint clientRelativeCoordinates = Win32.MACROS.MAKELPARAM( (ushort)lPointX, (ushort)lPointY); // IntPtr previousWindowCapture = Win32.Cursor.GetCapture() // COMMENTED BY CODEIT.RIGHT; int hwnd = windowHandle.ToInt32(); lock (OnMouseEventLock) { //Win32.Cursor.SetCapture(windowHandle); Win32.Windows.PostMessage(windowHandle, Win32.WM.MOUSEMOVE, (int)CurrentMK, clientRelativeCoordinates); Win32.Windows.PostMessage(windowHandle, Win32.WM.SETCURSOR, hwnd, Win32.MACROS.MAKELPARAM((ushort)Win32.WM.MOUSEMOVE, (ushort)Win32.HitTestValues.HTCLIENT)); Win32.Windows.PostMessage(windowHandle, Win32.WM.MOUSEACTIVATE, hwnd, Win32.MACROS.MAKELPARAM((ushort)wm, (ushort)Win32.HitTestValues.HTCLIENT)); Win32.Windows.PostMessage(windowHandle, wm, mouseData, clientRelativeCoordinates); Debug.WriteLine("OnMouseEvent SendMessage(" + windowHandle.ToString() + ", " + wm + ", " + mouseData + ", " + clientRelativeCoordinates + ", " + pointX + ", " + pointY + ", " + lPointX + ", " + lPointY + ", (" + CurrentMK + "), " + isButtonUpEvent); //Win32.Cursor.ReleaseCapture(); } }
private void OnKeyboardEventViaViq(uint vk, Win32.WindowHook.LLKHF flags, uint scan, uint time, Win32.CAS cas) { int wParam = (int)vk; Win32.WM wm = (((flags & Win32.WindowHook.LLKHF.UP) == Win32.WindowHook.LLKHF.UP) ? Win32.WM.KEYUP : Win32.WM.KEYDOWN); // TODO SYSKEYDOWN via Win32.WindowHook.LLKHF.AltKey ? uint lParam = 0x01; if (wm == Win32.WM.KEYUP) { lParam |= 0xC0000000; } uint scanCode = scan; if (scanCode > 0) { lParam |= ((scanCode & 0xFF) << 16); } if ((flags & Win32.WindowHook.LLKHF.UP) != Win32.WindowHook.LLKHF.UP) { if ((cas & Win32.CAS.CONTROL) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Control, (Win32.WindowHook.LLKHF) 0, (uint)0, time, (Win32.CAS) 0); } if ((cas & Win32.CAS.ALT) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Menu, (Win32.WindowHook.LLKHF) 0, (uint)0, time, (Win32.CAS) 0); flags |= Win32.WindowHook.LLKHF.ALTDOWN; } if ((cas & Win32.CAS.SHIFT) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Shift, (Win32.WindowHook.LLKHF) 0, (uint)0, time, (Win32.CAS) 0); } } Win32.SetKeyboardState(this.pressedKeys); Win32.Windows.SendMessage(WindowHandle, wm, wParam, lParam); // if keydown, translate message if (wm == Win32.WM.KEYDOWN) { Mubox.Win32.Windows.MSG msg = new Win32.Windows.MSG(); msg.hwnd = WindowHandle; msg.lParam = lParam; msg.message = wm; msg.pt = new Win32.Windows.POINT(); msg.time = Win32.SendInputApi.GetTickCount(); msg.wParam = (int)vk; Win32.Windows.TranslateMessage(ref msg); } if ((flags & Win32.WindowHook.LLKHF.UP) != Win32.WindowHook.LLKHF.UP) { if ((cas & Win32.CAS.CONTROL) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Control, Win32.WindowHook.LLKHF.UP, (uint)0, Win32.SendInputApi.GetTickCount(), (Win32.CAS) 0); } if ((cas & Win32.CAS.ALT) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Menu, Win32.WindowHook.LLKHF.UP, (uint)0, Win32.SendInputApi.GetTickCount(), (Win32.CAS) 0); } if ((cas & Win32.CAS.SHIFT) != 0) { OnKeyboardEventViaViq((uint)Win32.VK.Shift, Win32.WindowHook.LLKHF.UP, (uint)0, Win32.SendInputApi.GetTickCount(), (Win32.CAS) 0); } } }
private void OnMouseInputReceived(Model.Input.MouseInput mouseInput) { bool useVIQ = (Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_ABSOLUTE == (mouseInput.Flags & Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_ABSOLUTE)); // translate message and track MK changes Win32.WM wm = Win32.WM.USER; bool isButtonUpEvent = false; ushort wheelDelta = 0; Win32.SendInputApi.MouseEventFlags lFlags = useVIQ ? mouseInput.Flags ^ Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_ABSOLUTE : mouseInput.Flags; switch (lFlags) { case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_MOVE: wm = Win32.WM.MOUSEMOVE; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_LEFTDOWN: wm = Win32.WM.LBUTTONDOWN; CurrentMK |= Win32.Windows.MK.MK_LBUTTON; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_LEFTUP: wm = Win32.WM.LBUTTONUP; isButtonUpEvent = true; CurrentMK = (CurrentMK | Win32.Windows.MK.MK_LBUTTON) ^ Win32.Windows.MK.MK_LBUTTON; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_RIGHTDOWN: wm = Win32.WM.RBUTTONDOWN; CurrentMK |= Win32.Windows.MK.MK_RBUTTON; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_RIGHTUP: wm = Win32.WM.RBUTTONUP; CurrentMK = (CurrentMK | Win32.Windows.MK.MK_RBUTTON) ^ Win32.Windows.MK.MK_RBUTTON; isButtonUpEvent = true; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_MIDDLEDOWN: wm = Win32.WM.MBUTTONDOWN; CurrentMK |= Win32.Windows.MK.MK_MBUTTON; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_MIDDLEUP: wm = Win32.WM.MBUTTONUP; CurrentMK = (CurrentMK | Win32.Windows.MK.MK_MBUTTON) ^ Win32.Windows.MK.MK_MBUTTON; isButtonUpEvent = true; break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_XDOWN: wm = Win32.WM.XBUTTONDOWN; { var xbutton = Win32.MACROS.GET_XBUTTON_WPARAM(mouseInput.MouseData); wheelDelta = (ushort)xbutton; switch (xbutton) { case Win32.MACROS.XBUTTONS.XBUTTON1: CurrentMK |= Win32.Windows.MK.MK_XBUTTON1; break; case Win32.MACROS.XBUTTONS.XBUTTON2: CurrentMK |= Win32.Windows.MK.MK_XBUTTON2; break; default: Debug.WriteLine("UnsupportedButtonDown in MouseData(" + xbutton + ") for " + this.DisplayName); break; } } break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_XUP: wm = Win32.WM.XBUTTONUP; isButtonUpEvent = true; { var xbutton = Win32.MACROS.GET_XBUTTON_WPARAM(mouseInput.MouseData); wheelDelta = (ushort)xbutton; switch (xbutton) { case Win32.MACROS.XBUTTONS.XBUTTON1: CurrentMK = (CurrentMK | Win32.Windows.MK.MK_XBUTTON1) ^ Win32.Windows.MK.MK_XBUTTON1; break; case Win32.MACROS.XBUTTONS.XBUTTON2: CurrentMK = (CurrentMK | Win32.Windows.MK.MK_XBUTTON2) ^ Win32.Windows.MK.MK_XBUTTON2; break; default: Debug.WriteLine("UnsupportedButtonUp in MouseData(" + xbutton + ") for " + this.DisplayName); break; } } break; case Win32.SendInputApi.MouseEventFlags.MOUSEEVENTF_WHEEL: wheelDelta = Win32.MACROS.HIWORD(mouseInput.MouseData); wm = Win32.WM.MOUSEWHEEL; break; default: return; } mouseInput.MouseData = Win32.MACROS.MAKEWPARAM((ushort)CurrentMK, wheelDelta); // only use VIQ for "mouse clone" events if (!useVIQ) { Win32.SendInputApi.SendInputViaMSParams(mouseInput.Flags, mouseInput.Time, (int)mouseInput.Point.X, (int)mouseInput.Point.Y, mouseInput.MouseData); return; } // no target window? can't use if (WindowHandle == IntPtr.Zero) { Debug.WriteLine("NoWindowHandle Failed OnMouseInputReceived, Input Loss for " + this.DisplayName); return; } // can't resolve VIQ? can't use IntPtr windowInputQueue = WindowInputQueue; if (windowInputQueue == IntPtr.Zero) { Debug.WriteLine("NoWindowInputQueue Failed OnMouseInputReceived, Input Loss for " + this.DisplayName); return; } // denormalize coordinates Win32.Windows.RECT clientRect; Win32.Windows.GetClientRect(WindowHandle, out clientRect); int lPointX = (int)(((double)clientRect.Width / (double)65536) * mouseInput.Point.X); int lPointY = (int)(((double)clientRect.Height / (double)65536) * mouseInput.Point.Y); // prep action Action action = () => { Debug.WriteLine("MouseVIQAction for " + this.DisplayName); OnMouseEvent_Action((int)mouseInput.Point.X, (int)mouseInput.Point.Y, lPointX, lPointY, wm, mouseInput.MouseData, isButtonUpEvent); }; // resolve VIQ IntPtr foregroundWindowHandle; IntPtr foregroundInputQueue; if (!TryResolveViq(out foregroundInputQueue, out foregroundWindowHandle, DateTime.Now.AddMilliseconds(1000).Ticks)) { Debug.WriteLine("TryResolveVIQ Failed OnMouseInputReceived, Input Loss for " + this.DisplayName); return; } ActionViaViq(action, foregroundInputQueue, "OnMouseInputReceived"); }
public void AddBubbleMouseEvent(Action <Control, MouseEventArgs> action, bool?capture, Win32.WM message, Func <MouseButtons, MouseButtons> modifyButtons = null) { AddBubbleEvent(be => MouseEvent(be, action, capture, modifyButtons), message); }
public void AddBubbleKeyCharEvent(Action <Control, KeyEventArgs> action, Win32.WM message, KeyEventType keyEventType) { AddBubbleEvent(be => KeyCharEvent(be, action, keyEventType), message); }