Added workaround for zoom-in/zoom-out keys on Microsoft Digital 3000 keyboard. These keys report 0 as a device id, but no such device exists.

This commit is contained in:
the_fiddler 2010-11-09 15:19:58 +00:00
parent 529a376d77
commit e0736a69bc
2 changed files with 32 additions and 4 deletions

View file

@ -80,6 +80,16 @@ namespace OpenTK.Platform.Windows
// Discover keyboard devices: // Discover keyboard devices:
foreach (RawInputDeviceList dev in ridl) foreach (RawInputDeviceList dev in ridl)
{ {
ContextHandle id = new ContextHandle(dev.Device);
if (rawids.ContainsKey(id))
{
// Device already registered, mark as connected
KeyboardState state = keyboards[rawids[id]];
state.IsConnected = true;
keyboards[rawids[id]] = state;
continue;
}
string name = GetDeviceName(dev); string name = GetDeviceName(dev);
if (name.ToLower().Contains("root")) if (name.ToLower().Contains("root"))
{ {
@ -136,7 +146,16 @@ namespace OpenTK.Platform.Windows
{ {
RefreshDevices(); RefreshDevices();
} }
keyboard = keyboards[rawids[handle]];
if (keyboards.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 keyboard_handle = rawids.ContainsKey(handle) ? rawids[handle] : 0;
keyboard = keyboards[keyboard_handle];
// Generic control, shift, alt keys may be sent instead of left/right. // Generic control, shift, alt keys may be sent instead of left/right.
// It seems you have to explicitly register left/right events. // It seems you have to explicitly register left/right events.
@ -173,7 +192,7 @@ namespace OpenTK.Platform.Windows
lock (UpdateLock) lock (UpdateLock)
{ {
keyboards[rawids[handle]] = keyboard; keyboards[keyboard_handle] = keyboard;
return processed; return processed;
} }
} }

View file

@ -147,7 +147,16 @@ namespace OpenTK.Platform.Windows
{ {
RefreshDevices(); RefreshDevices();
} }
mouse = mice[rawids[handle]];
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_DOWN) != 0) mouse.EnableBit((int)MouseButton.Left);
if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) mouse.DisableBit((int)MouseButton.Left); if ((raw.ButtonFlags & RawInputMouseState.LEFT_BUTTON_UP) != 0) mouse.DisableBit((int)MouseButton.Left);
@ -176,7 +185,7 @@ namespace OpenTK.Platform.Windows
lock (UpdateLock) lock (UpdateLock)
{ {
mice[rawids[handle]] = mouse; mice[mouse_handle] = mouse;
return true; return true;
} }
} }