Corrected Windows.API.RawMouse class. Mouse input now works!
This commit is contained in:
parent
b660f5af9b
commit
21d6030a6a
5 changed files with 34 additions and 24 deletions
|
@ -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;
|
||||
//
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1755,45 +1755,34 @@ namespace OpenTK.Platform.Windows
|
|||
/// MOUSE_VIRTUAL_DESKTOP
|
||||
/// Mouse coordinates are mapped to the virtual desktop (for a multiple monitor system).
|
||||
/// </summary>
|
||||
//[FieldOffset(0)]
|
||||
public RawMouseFlags Flags; // USHORT
|
||||
public RawMouseFlags Flags; // USHORT in winuser.h, but only INT works -- USHORT returns 0.
|
||||
// /// <summary>
|
||||
// /// Reserved.
|
||||
// /// </summary>
|
||||
// [FieldOffset(2)]
|
||||
// ULONG Buttons;
|
||||
/// <summary>
|
||||
/// Transition state of the mouse buttons.
|
||||
/// </summary>
|
||||
//[FieldOffset(2)]
|
||||
public RawInputMouseState ButtonFlags;
|
||||
/// <summary>
|
||||
/// If usButtonFlags is RI_MOUSE_WHEEL, this member is a signed value that specifies the wheel delta.
|
||||
/// </summary>
|
||||
//[FieldOffset(4)]
|
||||
//public USHORT ButtonData;
|
||||
public SHORT ButtonData;
|
||||
/// <summary>
|
||||
/// Raw state of the mouse buttons.
|
||||
/// </summary>
|
||||
//[FieldOffset(6)]
|
||||
//public ULONG RawButtons;
|
||||
public LONG RawButtons;
|
||||
/// <summary>
|
||||
/// Motion in the X direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
|
||||
/// </summary>
|
||||
//[FieldOffset(10)]
|
||||
public LONG LastX;
|
||||
/// <summary>
|
||||
/// Motion in the Y direction. This is signed relative motion or absolute motion, depending on the value of usFlags.
|
||||
/// </summary>
|
||||
//[FieldOffset(14)]
|
||||
public LONG LastY;
|
||||
/// <summary>
|
||||
/// Device-specific additional information for the event.
|
||||
/// </summary>
|
||||
//[FieldOffset(18)]
|
||||
//public ULONG ExtraInformation;
|
||||
public LONG ExtraInformation;
|
||||
}
|
||||
|
||||
|
@ -2356,7 +2345,7 @@ namespace OpenTK.Platform.Windows
|
|||
/// <summary>
|
||||
/// Mouse indicator flags (found in winuser.h).
|
||||
/// </summary>
|
||||
public enum RawMouseFlags : short
|
||||
public enum RawMouseFlags : int//short
|
||||
{
|
||||
/// <summary>
|
||||
/// LastX/Y indicate relative motion.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue