Permalink
Browse files

Replication project for Mac OS mouse input issue, and fix. OpenTK iss…

…ues 3242 and 2800
  • Loading branch information...
1 parent 3c60987 commit 39c3f3f54324b80262d10fc5af82366224f79f4e @andykorth committed Dec 21, 2012
@@ -44,16 +44,16 @@
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>DEBUG;TRACE;</DefineConstants>
<DocumentationFile>
</DocumentationFile>
- <DebugSymbols>true</DebugSymbols>
+ <DebugSymbols>True</DebugSymbols>
<FileAlignment>4096</FileAlignment>
- <Optimize>false</Optimize>
+ <Optimize>False</Optimize>
<OutputPath>..\..\Binaries\OpenTK\Debug\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
@@ -62,15 +62,15 @@
<DebugType>full</DebugType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<FileAlignment>4096</FileAlignment>
- <Optimize>true</Optimize>
+ <Optimize>True</Optimize>
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
@@ -82,19 +82,19 @@
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
<DebugType>none</DebugType>
<WarningLevel>4</WarningLevel>
- <Optimize>true</Optimize>
+ <Optimize>True</Optimize>
<DefineConstants>TRACE;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Nsis|AnyCPU'">
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+ <AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<BaseAddress>285212672</BaseAddress>
<ConfigurationOverrideFile>
</ConfigurationOverrideFile>
<DefineConstants>TRACE;</DefineConstants>
<DocumentationFile>
</DocumentationFile>
<FileAlignment>4096</FileAlignment>
- <Optimize>true</Optimize>
+ <Optimize>True</Optimize>
<OutputPath>..\..\Binaries\OpenTK\Release\</OutputPath>
<RegisterForComInterop>False</RegisterForComInterop>
<RemoveIntegerChecks>False</RemoveIntegerChecks>
@@ -103,31 +103,26 @@
<DebugType>none</DebugType>
</PropertyGroup>
<PropertyGroup>
- <SignAssembly>true</SignAssembly>
+ <SignAssembly>True</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>..\..\OpenTK.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
<Name>System</Name>
- <Private>False</Private>
</Reference>
<Reference Include="System.Data">
<Name>System.Data</Name>
- <Private>False</Private>
</Reference>
<Reference Include="System.Drawing">
<Name>System.Drawing</Name>
- <Private>False</Private>
</Reference>
<Reference Include="System.Windows.Forms">
<Name>System.Windows.Forms</Name>
- <Private>False</Private>
</Reference>
<Reference Include="System.Xml">
<Name>System.Xml</Name>
- <Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -560,6 +555,9 @@
<None Include="..\OpenTK\OpenTK.dll.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
+ <Compile Include="OpenTK\Test\BasicMouseInput.cs">
+ <SubType>Code</SubType>
+ </Compile>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@@ -40,7 +40,12 @@ protected override void OnUpdateFrame(FrameEventArgs e)
{
// Here's the big test!
if(OpenTK.Input.Mouse.GetState()[MouseButton.Left]){
- Console.WriteLine("You clicked the left mouse button!");
+ Console.WriteLine("The left mouse button is down!");
+ }
+
+ // While we are here, test keyboard.
+ if(OpenTK.Input.Keyboard.GetState()[Key.A]){
+ Console.WriteLine("The A key is down!");
}
if (Keyboard[OpenTK.Input.Key.Escape])
@@ -124,15 +124,15 @@ void DeviceAdded(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef dev
{
if (!MouseDevices.ContainsKey(device))
{
- Debug.Print("Mouse device {0} discovered", device);
+ Debug.Print("Mouse device {0:x} discovered, sender is {1:x}", device, sender);
MouseState state = new MouseState();
state.IsConnected = true;
MouseIndexToDevice.Add(MouseDevices.Count, device);
MouseDevices.Add(device, state);
}
else
{
- Debug.Print("Mouse device {0} reconnected", device);
+ Debug.Print("Mouse device {0:x} reconnected, sender is {1:x}", device, sender);
MouseState state = MouseDevices[device];
state.IsConnected = true;
MouseDevices[device] = state;
@@ -144,23 +144,26 @@ void DeviceAdded(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef dev
{
if (!KeyboardDevices.ContainsKey(device))
{
- Debug.Print("Keyboard device {0} discovered", device);
+ Debug.Print("Keyboard device {0:x} discovered, sender is {1:x}", device, sender);
KeyboardState state = new KeyboardState();
state.IsConnected = true;
KeyboardIndexToDevice.Add(KeyboardDevices.Count, device);
KeyboardDevices.Add(device, state);
}
else
{
- Debug.Print("Keyboard device {0} reconnected", device);
+ Debug.Print("Keyboard device {0:x} reconnected, sender is {1:x}", device, sender);
KeyboardState state = KeyboardDevices[device];
state.IsConnected = true;
KeyboardDevices[device] = state;
}
}
+ // The device is not normally available in the InputValueCallback (HandleDeviceValueReceived), so we include
+ // the device identifier as the context variable, so we can identify it and figure out the device later.
+ // Thanks to Jase: http://www.opentk.com/node/2800
NativeMethods.IOHIDDeviceRegisterInputValueCallback(device,
- HandleDeviceValueReceived, IntPtr.Zero);
+ HandleDeviceValueReceived, device);
NativeMethods.IOHIDDeviceScheduleWithRunLoop(device, RunLoop, InputLoopMode);
}
}
@@ -170,7 +173,7 @@ void DeviceRemoved(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef d
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Mouse) &&
MouseDevices.ContainsKey(device))
{
- Debug.Print("Mouse device {0} disconnected", device);
+ Debug.Print("Mouse device {0:x} disconnected, sender is {1:x}", device, sender);
// Keep the device in case it comes back later on
MouseState state = MouseDevices[device];
@@ -181,7 +184,7 @@ void DeviceRemoved(IntPtr context, IOReturn res, IntPtr sender, IOHIDDeviceRef d
if (NativeMethods.IOHIDDeviceConformsTo(device, HIDPage.GenericDesktop, (int)HIDUsageGD.Keyboard) &&
KeyboardDevices.ContainsKey(device))
{
- Debug.Print("Keyboard device {0} disconnected", device);
+ Debug.Print("Keyboard device {0:x} disconnected, sender is {1:x}", device, sender);
// Keep the device in case it comes back later on
KeyboardState state = KeyboardDevices[device];
@@ -197,13 +200,15 @@ void DeviceValueReceived(IntPtr context, IOReturn res, IntPtr sender, IOHIDValue
{
MouseState mouse;
KeyboardState keyboard;
- if (MouseDevices.TryGetValue(sender, out mouse))
+ if (MouseDevices.TryGetValue(context, out mouse))
{
- MouseDevices[sender] = UpdateMouse(mouse, val);
+ MouseDevices[context] = UpdateMouse(mouse, val);
}
- else if (KeyboardDevices.TryGetValue(sender, out keyboard))
+ else if (KeyboardDevices.TryGetValue(context, out keyboard))
{
- KeyboardDevices[sender] = UpdateKeyboard(keyboard, val);
+ KeyboardDevices[context] = UpdateKeyboard(keyboard, val);
+ }else{
+ //Debug.Print ("Device {0:x} not found in list of keyboards or mice", sender);
}
}

0 comments on commit 39c3f3f

Please sign in to comment.