add wired-only keyboard special key handling code
This commit is contained in:
parent
4e2aa8172d
commit
8fde720c47
|
@ -65,66 +65,108 @@ private static void SpecialKeyStateChanged(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
byte num1 = buffer2[i];
|
byte num1 = buffer2[i];
|
||||||
}
|
}
|
||||||
if (asyncState[0] == 0x11)
|
|
||||||
{
|
// TODO: would be nice if we could replace this property with some auto-detection to figure out
|
||||||
switch (asyncState[1])
|
// if the user is using a wired or wireless keyboard based on the device information...
|
||||||
{
|
// not sure how to do this currently because I don't have a wireless keyboard to test with.
|
||||||
case 24:
|
if (AppleWirelessKeyboard.Properties.Settings.Default.WiredKeyboard)
|
||||||
{
|
{
|
||||||
EjectDown = true;
|
// This is probably a big ol' ugly hack... but it seems to work well so far.
|
||||||
FnDown = true;
|
//
|
||||||
if (KeyDown != null)
|
// With the wired Apple Keyboard I have (http://store.apple.com/us/product/MB110LL/B), this whole method
|
||||||
KeyDown(AppleKeyboardSpecialKeys.Eject);
|
// _only_ does anything when the Eject key is pressed/released. No other keys or combination of keys
|
||||||
}
|
// that I tried causes the SpecialKeyStateChanged event to fire. This is using the default driver that
|
||||||
break;
|
// Windows 7 installs when I first plugged in my keyboard. (FWIW, the Apple driver from Lion's BootCamp
|
||||||
case 16:
|
// files didn't change anything).
|
||||||
{
|
//
|
||||||
if (EjectDown)
|
// With the wired keyboard, the bytes in asyncState will be different then the original code here is
|
||||||
{
|
// expecting (which is for the wireless keyboard).
|
||||||
EjectDown = false;
|
//
|
||||||
if (KeyUp != null)
|
// Basically, when using the wired keyboard:
|
||||||
KeyUp(AppleKeyboardSpecialKeys.Eject);
|
// * when the Eject key is pressed: (asyncState[0] == 0x0 && asyncState[1] == 0x8) == true
|
||||||
}
|
// * when the Eject key is released: (asyncState[0] == 0x0 && asyncState[1] == 0x0) == true
|
||||||
FnDown = true;
|
//
|
||||||
if (KeyDown != null)
|
// This _appears_ to be safe for use with the wired keyboard because, as noted above, no other keys
|
||||||
KeyDown(AppleKeyboardSpecialKeys.Fn);
|
// or combinations of keys cause this method to be fired in the first place.
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 8:
|
Debug.WriteLine(String.Format("{0}, {1}", asyncState[0], asyncState[1]));
|
||||||
{
|
if (asyncState[0] == 0x0 && asyncState[1] == 0x8)
|
||||||
if (FnDown)
|
{
|
||||||
{
|
EjectDown = true;
|
||||||
FnDown = false;
|
KeyDown(AppleKeyboardSpecialKeys.Eject);
|
||||||
if (KeyUp != null)
|
}
|
||||||
KeyUp(AppleKeyboardSpecialKeys.Fn);
|
else if (asyncState[0] == 0x0 && asyncState[1] == 0x0)
|
||||||
}
|
{
|
||||||
EjectDown = true;
|
EjectDown = false;
|
||||||
if (KeyDown != null)
|
KeyUp(AppleKeyboardSpecialKeys.Eject);
|
||||||
KeyDown(AppleKeyboardSpecialKeys.Eject);
|
}
|
||||||
}
|
}
|
||||||
break;
|
else
|
||||||
case 0:
|
{
|
||||||
{
|
// Original code to handle the wireless keyboard left completely intact.
|
||||||
if (EjectDown)
|
|
||||||
{
|
if (asyncState[0] == 0x11)
|
||||||
EjectDown = false;
|
{
|
||||||
if (KeyUp != null)
|
switch (asyncState[1])
|
||||||
KeyUp(AppleKeyboardSpecialKeys.Eject);
|
{
|
||||||
}
|
case 24:
|
||||||
if (FnDown)
|
{
|
||||||
{
|
EjectDown = true;
|
||||||
FnDown = false;
|
FnDown = true;
|
||||||
if (KeyUp != null)
|
if (KeyDown != null)
|
||||||
KeyUp(AppleKeyboardSpecialKeys.Fn);
|
KeyDown(AppleKeyboardSpecialKeys.Eject);
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
break;
|
case 16:
|
||||||
}
|
{
|
||||||
}
|
if (EjectDown)
|
||||||
else if (asyncState[0] == 0x13)
|
{
|
||||||
{
|
EjectDown = false;
|
||||||
CurrentPowerButtonIsDown = asyncState[1] == 1;
|
if (KeyUp != null)
|
||||||
}
|
KeyUp(AppleKeyboardSpecialKeys.Eject);
|
||||||
|
}
|
||||||
|
FnDown = true;
|
||||||
|
if (KeyDown != null)
|
||||||
|
KeyDown(AppleKeyboardSpecialKeys.Fn);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
{
|
||||||
|
if (FnDown)
|
||||||
|
{
|
||||||
|
FnDown = false;
|
||||||
|
if (KeyUp != null)
|
||||||
|
KeyUp(AppleKeyboardSpecialKeys.Fn);
|
||||||
|
}
|
||||||
|
EjectDown = true;
|
||||||
|
if (KeyDown != null)
|
||||||
|
KeyDown(AppleKeyboardSpecialKeys.Eject);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
{
|
||||||
|
if (EjectDown)
|
||||||
|
{
|
||||||
|
EjectDown = false;
|
||||||
|
if (KeyUp != null)
|
||||||
|
KeyUp(AppleKeyboardSpecialKeys.Eject);
|
||||||
|
}
|
||||||
|
if (FnDown)
|
||||||
|
{
|
||||||
|
FnDown = false;
|
||||||
|
if (KeyUp != null)
|
||||||
|
KeyUp(AppleKeyboardSpecialKeys.Fn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (asyncState[0] == 0x13)
|
||||||
|
{
|
||||||
|
CurrentPowerButtonIsDown = asyncState[1] == 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
_stream.BeginRead(asyncState, 0, asyncState.Length, new AsyncCallback(SpecialKeyStateChanged), asyncState);
|
_stream.BeginRead(asyncState, 0, asyncState.Length, new AsyncCallback(SpecialKeyStateChanged), asyncState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue