public bool ProcessMouseEvent(RawInput rin) { RawMouse raw = rin.Data.Mouse; ContextHandle handle = new ContextHandle(rin.Header.Device); MouseState mouse; if (!rawids.ContainsKey(handle)) { RefreshDevices(); } if (mice.Count == 0) { return(false); } // Note:For some reason, my Microsoft Digital 3000 keyboard reports 0 // as rin.Header.Device for the "zoom-in/zoom-out" buttons. // That's problematic, because no device has a "0" id. // As a workaround, we'll add those buttons to the first device (if any). int mouse_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0; mouse = mice[mouse_handle]; if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Left); } if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Left); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Right); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Right); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Middle); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Middle); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button1); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0) { mouse.DisableBit((int)MouseButton.Button1); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button2); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0) { mouse.DisableBit((int)MouseButton.Button2); } if ((raw.ButtonFlags & RawInputMouseState.WHEEL) != 0) { mouse.WheelPrecise += (short)raw.ButtonData / 120.0f; } if ((raw.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0) { mouse.X = raw.LastX; mouse.Y = raw.LastY; } else { // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted. mouse.X += raw.LastX; mouse.Y += raw.LastY; } lock (UpdateLock) { mice[mouse_handle] = mouse; return(true); } }
public bool ProcessMouseEvent(IntPtr raw_buffer) { bool processed = false; RawInput rin; if (Functions.GetRawInputData(raw_buffer, out rin) > 0) { RawMouse raw = rin.Data.Mouse; ContextHandle handle = new ContextHandle(rin.Header.Device); MouseState mouse; if (!rawids.ContainsKey(handle)) { RefreshDevices(); } if (mice.Count == 0) { return(false); } // Note:For some reason, my Microsoft Digital 3000 keyboard reports 0 // as rin.Header.Device for the "zoom-in/zoom-out" buttons. // That's problematic, because no device has a "0" id. // As a workaround, we'll add those buttons to the first device (if any). int mouse_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0; mouse = mice[mouse_handle]; // Set and release capture of the mouse to fix http://www.opentk.com/node/2133, Patch by Artfunkel if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Left); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Left); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Right); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Right); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Middle); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0) { mouse.DisableBit((int)MouseButton.Middle); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button1); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0) { mouse.DisableBit((int)MouseButton.Button1); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0) { mouse.EnableBit((int)MouseButton.Button2); Functions.SetCapture(Window); } if ((raw.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0) { mouse.DisableBit((int)MouseButton.Button2); Functions.ReleaseCapture(); } if ((raw.ButtonFlags & RawInputMouseState.WHEEL) != 0) { mouse.SetScrollRelative(0, (short)raw.ButtonData / 120.0f); } if ((raw.ButtonFlags & RawInputMouseState.HWHEEL) != 0) { mouse.SetScrollRelative((short)raw.ButtonData / 120.0f, 0); } if ((raw.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != 0) { mouse.X = raw.LastX; mouse.Y = raw.LastY; } else { // Seems like MOUSE_MOVE_RELATIVE is the default, unless otherwise noted. mouse.X += raw.LastX; mouse.Y += raw.LastY; } lock (UpdateLock) { mice[mouse_handle] = mouse; processed = true; } } return(processed); }
public bool ProcessMouseEvent(RawInput rin) { RawMouse rawMouse = rin.Data.Mouse; ContextHandle key = new ContextHandle(rin.Header.Device); if (!this.rawids.ContainsKey(key)) { this.RefreshDevices(); } if (this.mice.Count == 0) { return(false); } int index = this.rawids.ContainsKey(key) ? this.rawids[key] : 0; MouseState mouseState = this.mice[index]; if ((rawMouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != (RawInputMouseState)0) { mouseState.EnableBit(0); } if ((rawMouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != (RawInputMouseState)0) { mouseState.DisableBit(0); } if ((rawMouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != (RawInputMouseState)0) { mouseState.EnableBit(2); } if ((rawMouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != (RawInputMouseState)0) { mouseState.DisableBit(2); } if ((rawMouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != (RawInputMouseState)0) { mouseState.EnableBit(1); } if ((rawMouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != (RawInputMouseState)0) { mouseState.DisableBit(1); } if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != (RawInputMouseState)0) { mouseState.EnableBit(3); } if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != (RawInputMouseState)0) { mouseState.DisableBit(3); } if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != (RawInputMouseState)0) { mouseState.EnableBit(4); } if ((rawMouse.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != (RawInputMouseState)0) { mouseState.DisableBit(4); } if ((rawMouse.ButtonFlags & RawInputMouseState.WHEEL) != (RawInputMouseState)0) { mouseState.WheelPrecise += (float)(short)rawMouse.ButtonData / 120f; } if ((rawMouse.Flags & RawMouseFlags.MOUSE_MOVE_ABSOLUTE) != RawMouseFlags.MOUSE_MOVE_RELATIVE) { mouseState.X = rawMouse.LastX; mouseState.Y = rawMouse.LastY; } else { mouseState.X += rawMouse.LastX; mouseState.Y += rawMouse.LastY; } lock (this.UpdateLock) { this.mice[index] = mouseState; return(true); } }