diff --git a/Source/Examples/Tests/S04_Input_Logger.Designer.cs b/Source/Examples/Tests/S04_Input_Logger.Designer.cs
index 9e07a862..9ee9573e 100644
--- a/Source/Examples/Tests/S04_Input_Logger.Designer.cs
+++ b/Source/Examples/Tests/S04_Input_Logger.Designer.cs
@@ -204,6 +204,7 @@
//
this.textBox1.Location = new System.Drawing.Point(66, 44);
this.textBox1.Name = "textBox1";
+ this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(73, 20);
this.textBox1.TabIndex = 2;
//
@@ -211,6 +212,7 @@
//
this.textBox2.Location = new System.Drawing.Point(66, 71);
this.textBox2.Name = "textBox2";
+ this.textBox2.ReadOnly = true;
this.textBox2.Size = new System.Drawing.Size(73, 20);
this.textBox2.TabIndex = 3;
//
@@ -218,6 +220,7 @@
//
this.textBox3.Location = new System.Drawing.Point(66, 98);
this.textBox3.Name = "textBox3";
+ this.textBox3.ReadOnly = true;
this.textBox3.Size = new System.Drawing.Size(73, 20);
this.textBox3.TabIndex = 4;
//
@@ -225,6 +228,7 @@
//
this.textBox4.Location = new System.Drawing.Point(66, 125);
this.textBox4.Name = "textBox4";
+ this.textBox4.ReadOnly = true;
this.textBox4.Size = new System.Drawing.Size(73, 20);
this.textBox4.TabIndex = 5;
//
diff --git a/Source/Examples/Tests/S04_Input_Logger.cs b/Source/Examples/Tests/S04_Input_Logger.cs
index d3a4b014..5ea85709 100644
--- a/Source/Examples/Tests/S04_Input_Logger.cs
+++ b/Source/Examples/Tests/S04_Input_Logger.cs
@@ -30,6 +30,7 @@ namespace Examples.Tests
WindowInfo info = new WindowInfo(this);
driver = new InputDriver(info);
Debug.Print("Keyboard count: {0}", driver.Keyboard.Count);
+ Debug.Print("Mouse count: {0}", driver.Mouse.Count);
switch (driver.Keyboard.Count)
{
@@ -73,8 +74,8 @@ namespace Examples.Tests
foreach (Mouse m in driver.Mouse)
{
ChooseMouse.Items.Add(String.Format("Mouse {0} ({1})", ++i, m.Description));
- //m.ButtonDown += LogMouseButtonDown;
- //m.ButtonUp += LogMouseButtonUp;
+ m.ButtonDown += LogMouseButtonDown;
+ m.ButtonUp += LogMouseButtonUp;
//m.Move += LogMouseMove;
}
if (i > 0)
@@ -91,12 +92,14 @@ namespace Examples.Tests
void LogMouseButtonDown(IMouse sender, MouseButton button)
{
- throw new Exception("The method or operation is not implemented.");
+ Debug.Print("Mouse button down: {0} on device: {1}", button, sender.DeviceID);
+ MouseButtons.Items.Add(button);
}
void LogMouseButtonUp(IMouse sender, MouseButton button)
{
- throw new Exception("The method or operation is not implemented.");
+ Debug.Print("Mouse button up: {0} on device: {1}", button, sender.DeviceID);
+ MouseButtons.Items.Remove(button);
}
void LogMouseMove(IMouse sender, MouseMoveData key)
@@ -112,6 +115,7 @@ namespace Examples.Tests
void LogKeyUp(object sender, Key key)
{
+ Debug.Print("Key up: {0} on device: {1}", key, (sender as Keyboard).DeviceID);
keyboardListBoxes[(sender as Keyboard).DeviceID].Items.Remove(key);
}
diff --git a/Source/OpenTK/Input/Mouse.cs b/Source/OpenTK/Input/Mouse.cs
index 71c56233..49229933 100644
--- a/Source/OpenTK/Input/Mouse.cs
+++ b/Source/OpenTK/Input/Mouse.cs
@@ -95,6 +95,14 @@ namespace OpenTK.Input
{
internal set
{
+ if (ButtonDown != null && value && !button[(int)b])
+ {
+ ButtonDown(this, b);
+ }
+ else if (ButtonUp != null && !value && button[(int)b])
+ {
+ ButtonUp(this, b);
+ }
button[(int)b] = value;
}
diff --git a/Source/OpenTK/Platform/Windows/API.cs b/Source/OpenTK/Platform/Windows/API.cs
index 7ca2f5b8..6756d519 100644
--- a/Source/OpenTK/Platform/Windows/API.cs
+++ b/Source/OpenTK/Platform/Windows/API.cs
@@ -1755,45 +1755,34 @@ namespace OpenTK.Platform.Windows
/// MOUSE_VIRTUAL_DESKTOP
/// Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).
///
- //[FieldOffset(0)]
- public RawMouseFlags Flags; // USHORT
+ public RawMouseFlags Flags; // USHORT in winuser.h, but only INT works -- USHORT returns 0.
// ///
// /// Reserved.
// ///
- // [FieldOffset(2)]
// ULONG Buttons;
///
/// Transition state of the mouse buttons.
///
- //[FieldOffset(2)]
public RawInputMouseState ButtonFlags;
///
/// If usButtonFlags is RI_MOUSE_WHEEL, this member is a signed value that specifies the wheel delta.
///
- //[FieldOffset(4)]
- //public USHORT ButtonData;
public SHORT ButtonData;
///
/// Raw state of the mouse buttons.
///
- //[FieldOffset(6)]
- //public ULONG RawButtons;
public LONG RawButtons;
///
/// Motion in the X direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
///
- //[FieldOffset(10)]
public LONG LastX;
///
/// Motion in the Y direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
///
- //[FieldOffset(14)]
public LONG LastY;
///
/// Device-specific additional information for the event.
///
- //[FieldOffset(18)]
- //public ULONG ExtraInformation;
public LONG ExtraInformation;
}
@@ -2356,7 +2345,7 @@ namespace OpenTK.Platform.Windows
///
/// Mouse indicator flags (found in winuser.h).
///
- public enum RawMouseFlags : short
+ public enum RawMouseFlags : int//short
{
///
/// LastX/Y indicate relative motion.
diff --git a/Source/OpenTK/Platform/Windows/WinRawMouse.cs b/Source/OpenTK/Platform/Windows/WinRawMouse.cs
index 8dc868cd..9b47d7c0 100644
--- a/Source/OpenTK/Platform/Windows/WinRawMouse.cs
+++ b/Source/OpenTK/Platform/Windows/WinRawMouse.cs
@@ -168,11 +168,16 @@ namespace OpenTK.Platform.Windows
switch (rin.Header.Type)
{
case RawInputDeviceType.MOUSE:
- mouse[MouseButton.Left] = rin.Data.Mouse.ButtonFlags == RawInputMouseState.LEFT_BUTTON_DOWN;
- mouse[MouseButton.Right] = rin.Data.Mouse.ButtonFlags == RawInputMouseState.RIGHT_BUTTON_DOWN;
- mouse[MouseButton.Middle] = rin.Data.Mouse.ButtonFlags == RawInputMouseState.MIDDLE_BUTTON_DOWN;
- mouse[MouseButton.Button1] = rin.Data.Mouse.ButtonFlags == RawInputMouseState.BUTTON_4_DOWN;
- mouse[MouseButton.Button2] = rin.Data.Mouse.ButtonFlags == RawInputMouseState.BUTTON_5_DOWN;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_DOWN) != 0) mouse[MouseButton.Left] = true;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) mouse[MouseButton.Left] = false;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_DOWN) != 0) mouse[MouseButton.Right] = true;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.RIGHT_BUTTON_UP) != 0) mouse[MouseButton.Right] = false;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_DOWN) != 0) mouse[MouseButton.Middle] = true;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.MIDDLE_BUTTON_UP) != 0) mouse[MouseButton.Middle] = false;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.BUTTON_4_DOWN) != 0) mouse[MouseButton.Button1] = true;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.BUTTON_4_UP) != 0) mouse[MouseButton.Button1] = false;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.BUTTON_5_DOWN) != 0) mouse[MouseButton.Button2] = true;
+ if ((rin.Data.Mouse.ButtonFlags & RawInputMouseState.BUTTON_5_UP) != 0) mouse[MouseButton.Button2] = false;
if (rin.Data.Mouse.ButtonFlags == RawInputMouseState.WHEEL)
{
@@ -181,8 +186,8 @@ namespace OpenTK.Platform.Windows
if (rin.Data.Mouse.Flags == RawMouseFlags.MOUSE_MOVE_ABSOLUTE)
{
- mouse.DeltaX = mouse.X - rin.Data.Mouse.LastX;
- mouse.DeltaY = mouse.Y - rin.Data.Mouse.LastY;
+ mouse.DeltaX = rin.Data.Mouse.LastX - mouse.X;
+ mouse.DeltaY = rin.Data.Mouse.LastY - mouse.Y;
mouse.X = rin.Data.Mouse.LastX;
mouse.Y = rin.Data.Mouse.LastY;
}