From bd64c5494010200a873a6050e533aca8bb7a379c Mon Sep 17 00:00:00 2001 From: gered Date: Mon, 28 Jan 2013 14:15:37 -0500 Subject: [PATCH] add new option to allow Eject key emulation of the Fn key This allows Wired Keyboard users to press Eject + [function key] and have the same thing happen that what would happen when Fn + [function key] was pressed on a Wireless keyboard. Essentially making Eject the Fn key. However, when this option is enabled, you can no longer toggle FMode on/off using the Eject key (obviously). --- AppleWirelessKeyboard/AppleKeyboardHID2.cs | 24 +++++++++++++++---- AppleWirelessKeyboard/KeyboardHandler.cs | 9 +++++-- .../Properties/Settings.Designer.cs | 14 ++++++++++- .../Properties/Settings.settings | 3 +++ AppleWirelessKeyboard/app.config | 3 +++ 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/AppleWirelessKeyboard/AppleKeyboardHID2.cs b/AppleWirelessKeyboard/AppleKeyboardHID2.cs index 691f6dc..a6f4cb9 100644 --- a/AppleWirelessKeyboard/AppleKeyboardHID2.cs +++ b/AppleWirelessKeyboard/AppleKeyboardHID2.cs @@ -93,13 +93,29 @@ private static void SpecialKeyStateChanged(IAsyncResult ar) Debug.WriteLine(String.Format("{0}, {1}", asyncState[0], asyncState[1])); if (asyncState[0] == 0x0 && asyncState[1] == 0x8) { - EjectDown = true; - KeyDown(AppleKeyboardSpecialKeys.Eject); + if (AppleWirelessKeyboard.Properties.Settings.Default.WiredHoldEjectForFn) + { + FnDown = true; + KeyDown(AppleKeyboardSpecialKeys.Fn); + } + else + { + EjectDown = true; + KeyDown(AppleKeyboardSpecialKeys.Eject); + } } else if (asyncState[0] == 0x0 && asyncState[1] == 0x0) { - EjectDown = false; - KeyUp(AppleKeyboardSpecialKeys.Eject); + if (AppleWirelessKeyboard.Properties.Settings.Default.WiredHoldEjectForFn) + { + FnDown = false; + KeyUp(AppleKeyboardSpecialKeys.Fn); + } + else + { + EjectDown = false; + KeyUp(AppleKeyboardSpecialKeys.Eject); + } } } else diff --git a/AppleWirelessKeyboard/KeyboardHandler.cs b/AppleWirelessKeyboard/KeyboardHandler.cs index 23525b3..2f520ee 100644 --- a/AppleWirelessKeyboard/KeyboardHandler.cs +++ b/AppleWirelessKeyboard/KeyboardHandler.cs @@ -19,7 +19,7 @@ public static bool FMode { get { - return AppleWirelessKeyboard.Properties.Settings.Default.FMode; + return AppleWirelessKeyboard.Properties.Settings.Default.FMode; } set { @@ -44,7 +44,12 @@ public static void HandleEject() public static bool HandleKeyDown(KeyboardListener.KeyHookEventArgs e) { - bool F = (FMode || e.ModifierFn) && !e.ModifierAnyNative; + bool F; + if (AppleWirelessKeyboard.Properties.Settings.Default.WiredKeyboard && + AppleWirelessKeyboard.Properties.Settings.Default.WiredHoldEjectForFn) + F = e.ModifierFn && !e.ModifierAnyNative; + else + F = (FMode || e.ModifierFn) && !e.ModifierAnyNative; switch (e.Key) { diff --git a/AppleWirelessKeyboard/Properties/Settings.Designer.cs b/AppleWirelessKeyboard/Properties/Settings.Designer.cs index ad6c8f9..be769a6 100644 --- a/AppleWirelessKeyboard/Properties/Settings.Designer.cs +++ b/AppleWirelessKeyboard/Properties/Settings.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.269 +// Runtime Version:4.0.30319.296 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -94,5 +94,17 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio this["WiredKeyboard"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool WiredHoldEjectForFn { + get { + return ((bool)(this["WiredHoldEjectForFn"])); + } + set { + this["WiredHoldEjectForFn"] = value; + } + } } } diff --git a/AppleWirelessKeyboard/Properties/Settings.settings b/AppleWirelessKeyboard/Properties/Settings.settings index 947d87e..bfb1bd5 100644 --- a/AppleWirelessKeyboard/Properties/Settings.settings +++ b/AppleWirelessKeyboard/Properties/Settings.settings @@ -20,5 +20,8 @@ False + + False + \ No newline at end of file diff --git a/AppleWirelessKeyboard/app.config b/AppleWirelessKeyboard/app.config index edb9b1e..b3e5dd1 100644 --- a/AppleWirelessKeyboard/app.config +++ b/AppleWirelessKeyboard/app.config @@ -25,6 +25,9 @@ False + + False +