Skip to content

Commit c902e4c

Browse files
committed
Patched in diff file applefn.patch for Apple fn key
qmk#2179 From Issue qmk#2179 of qmk/qmk_firmware, user fauxpark mentions how to enable the Apple 'fn' key in QMK. A link to applefn.patch is in the issue link above, and was patched into qmk_firmware with this command: (applefn.patch was already copied into ./qmk_firmware) ```c % cd qmk_firmware % patch -ruN -d ./ < applefn.patch ``` In order to be able to use the Apple fn key keycode -- KC_APPLE_FN, or alternatively, KC_APFN, you must define the following directives in the config.h file for your keyboard's config.h: ```c #define VENDOR_ID 0x05ac #define PRODUCT_ID 0x024f #define APPLE_FN_ENABLE ``` macOS must "think" your keyboard is one of their own -- the PRODUCT_ID corresponds to the Apple Pro Keyboard. This commit already has the patch applied, so the KC_APPLE_FN (KC_APFN) keycode may be used in all layouts from here on out.
1 parent 9fb9905 commit c902e4c

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed

common_features.mk

+4
Original file line numberDiff line numberDiff line change
@@ -521,3 +521,7 @@ ifeq ($(strip $(AUTO_SHIFT_ENABLE)), yes)
521521
OPT_DEFS += -DAUTO_SHIFT_MODIFIERS
522522
endif
523523
endif
524+
525+
ifeq ($(strip $(APPLE_FN_ENABLE)), yes)
526+
OPT_DEFS += -DAPPLE_FN_ENABLE
527+
endif

quantum/keymap_common.c

+5
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ action_t action_for_key(uint8_t layer, keypos_t key) {
6868
action.code = ACTION_USAGE_CONSUMER(KEYCODE2CONSUMER(keycode));
6969
break;
7070
#endif
71+
#ifdef APPLE_FN_ENABLE
72+
case KC_APPLE_FN:
73+
action.code = ACTION_APPLE_FN();
74+
break;
75+
#endif
7176
#ifdef MOUSEKEY_ENABLE
7277
case KC_MS_UP ... KC_MS_ACCEL2:
7378
action.code = ACTION_MOUSEKEY(keycode);

tmk_core/common/action.c

+25
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,16 @@ void process_action(keyrecord_t *record, action_t action) {
389389
}
390390
break;
391391
#endif
392+
#ifdef APPLE_FN_ENABLE
393+
/* Apple Fn */
394+
case ACT_APPLE_FN:
395+
if (event.pressed) {
396+
register_code(KC_APPLE_FN);
397+
} else {
398+
unregister_code(KC_APPLE_FN);
399+
}
400+
break;
401+
#endif
392402
#ifdef MOUSEKEY_ENABLE
393403
/* Mouse key */
394404
case ACT_MOUSEKEY:
@@ -806,6 +816,12 @@ void register_code(uint8_t code) {
806816
else if
807817
IS_CONSUMER(code) { host_consumer_send(KEYCODE2CONSUMER(code)); }
808818
#endif
819+
#ifdef APPLE_FN_ENABLE
820+
else if IS_APPLE_FN(code) {
821+
add_key(code);
822+
send_keyboard_report();
823+
}
824+
#endif
809825
#ifdef MOUSEKEY_ENABLE
810826
else if
811827
IS_MOUSEKEY(code) {
@@ -870,6 +886,12 @@ void unregister_code(uint8_t code) {
870886
IS_SYSTEM(code) { host_system_send(0); }
871887
else if
872888
IS_CONSUMER(code) { host_consumer_send(0); }
889+
#ifdef APPLE_FN_ENABLE
890+
else if IS_APPLE_FN(code) {
891+
del_key(code);
892+
send_keyboard_report();
893+
}
894+
#endif
873895
#ifdef MOUSEKEY_ENABLE
874896
else if
875897
IS_MOUSEKEY(code) {
@@ -1053,6 +1075,9 @@ void debug_action(action_t action) {
10531075
case ACT_USAGE:
10541076
dprint("ACT_USAGE");
10551077
break;
1078+
case ACT_APPLE_FN:
1079+
dprint("ACT_APPLE_FN");
1080+
break;
10561081
case ACT_MOUSEKEY:
10571082
dprint("ACT_MOUSEKEY");
10581083
break;

tmk_core/common/action_code.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5151
* ACT_SWAP_HANDS(0110):
5252
* 0110|xxxx| keycode Swap hands (keycode on tap, or options)
5353
*
54-
* 0111|xxxx xxxx xxxx (reserved)
54+
* ACT_APPLE_FN(0111):
55+
* 0111|0000|0000|0000 Apple Fn
5556
*
5657
* Layer Actions(10xx)
5758
* -------------------
@@ -106,6 +107,8 @@ enum action_kind_id {
106107
ACT_MOUSEKEY = 0b0101,
107108
/* One-hand Support */
108109
ACT_SWAP_HANDS = 0b0110,
110+
/* Apple Fn */
111+
ACT_APPLE_FN = 0b0111,
109112
/* Layer Actions */
110113
ACT_LAYER = 0b1000,
111114
ACT_LAYER_MODS = 0b1001,
@@ -216,6 +219,7 @@ enum mods_codes {
216219
enum usage_pages { PAGE_SYSTEM, PAGE_CONSUMER };
217220
#define ACTION_USAGE_SYSTEM(id) ACTION(ACT_USAGE, PAGE_SYSTEM << 10 | (id))
218221
#define ACTION_USAGE_CONSUMER(id) ACTION(ACT_USAGE, PAGE_CONSUMER << 10 | (id))
222+
#define ACTION_APPLE_FN() ACTION(ACT_APPLE_FN, 0)
219223
#define ACTION_MOUSEKEY(key) ACTION(ACT_MOUSEKEY, key)
220224

221225
/** \brief Layer Actions

tmk_core/common/keycode.h

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3434
#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF))
3535
#define IS_SYSTEM(code) (KC_PWR <= (code) && (code) <= KC_WAKE)
3636
#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_BRID)
37+
#define IS_APPLE_FN(code) (KC_APFN == (code))
3738

3839
#define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31)
3940

@@ -191,6 +192,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
191192
#define KC_BRIU KC_BRIGHTNESS_UP
192193
#define KC_BRID KC_BRIGHTNESS_DOWN
193194

195+
/* Apple Fn */
196+
#define KC_APFN KC_APPLE_FN
197+
194198
/* System Specific */
195199
#define KC_BRMU KC_PAUSE
196200
#define KC_BRMD KC_SCROLLLOCK
@@ -484,6 +488,9 @@ enum internal_special_keycodes {
484488
KC_BRIGHTNESS_UP,
485489
KC_BRIGHTNESS_DOWN,
486490

491+
/* Apple Fn */
492+
KC_APPLE_FN,
493+
487494
/* Fn keys */
488495
KC_FN0 = 0xC0,
489496
KC_FN1,

tmk_core/common/report.c

+12
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,12 @@ void del_key_bit(report_keyboard_t* keyboard_report, uint8_t code) {
231231
* FIXME: Needs doc
232232
*/
233233
void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) {
234+
#ifdef APPLE_FN_ENABLE
235+
if IS_APPLE_FN(key) {
236+
keyboard_report->reserved = 1;
237+
return;
238+
}
239+
#endif
234240
#ifdef NKRO_ENABLE
235241
if (keyboard_protocol && keymap_config.nkro) {
236242
add_key_bit(keyboard_report, key);
@@ -245,6 +251,12 @@ void add_key_to_report(report_keyboard_t* keyboard_report, uint8_t key) {
245251
* FIXME: Needs doc
246252
*/
247253
void del_key_from_report(report_keyboard_t* keyboard_report, uint8_t key) {
254+
#ifdef APPLE_FN_ENABLE
255+
if IS_APPLE_FN(key) {
256+
keyboard_report->reserved = 0;
257+
return;
258+
}
259+
#endif
248260
#ifdef NKRO_ENABLE
249261
if (keyboard_protocol && keymap_config.nkro) {
250262
del_key_bit(keyboard_report, key);

tmk_core/protocol/usb_descriptor.c

+12
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,22 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM KeyboardReport[] = {
6767
HID_RI_REPORT_COUNT(8, 0x08),
6868
HID_RI_REPORT_SIZE(8, 0x01),
6969
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
70+
71+
#ifdef APPLE_FN_ENABLE
72+
HID_RI_USAGE_PAGE(8, 0xFF), // AppleVendor Top Case
73+
HID_RI_USAGE(8, 0x03), // KeyboardFn
74+
HID_RI_LOGICAL_MINIMUM(8, 0x00),
75+
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
76+
HID_RI_REPORT_COUNT(8, 0x01),
77+
HID_RI_REPORT_SIZE(8, 0x08),
78+
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
79+
#else
7080
// Reserved (1 byte)
7181
HID_RI_REPORT_COUNT(8, 0x01),
7282
HID_RI_REPORT_SIZE(8, 0x08),
7383
HID_RI_INPUT(8, HID_IOF_CONSTANT),
84+
#endif
85+
7486
// Keycodes (6 bytes)
7587
HID_RI_USAGE_PAGE(8, 0x07), // Keyboard/Keypad
7688
HID_RI_USAGE_MINIMUM(8, 0x00),

tmk_core/protocol/vusb/vusb.c

+12
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,22 @@ const PROGMEM uchar keyboard_hid_report[] = {
380380
0x95, 0x08, // Report Count (8)
381381
0x75, 0x01, // Report Size (1)
382382
0x81, 0x02, // Input (Data, Variable, Absolute)
383+
384+
#ifdef APPLE_FN_ENABLE
385+
0x05, 0xFF, // Usage Page (AppleVendor Top Case)
386+
0x09, 0x03, // Usage (KeyboardFn)
387+
0x15, 0x00, // Logical Minimum (0)
388+
0x25, 0x01, // Logical Maximum (1)
389+
0x95, 0x01, // Report Count (1)
390+
0x75, 0x08, // Report Size (8)
391+
0x81, 0x02, // Input (Data, Variable, Absolute)
392+
#else
383393
// Reserved (1 byte)
384394
0x95, 0x01, // Report Count (1)
385395
0x75, 0x08, // Report Size (8)
386396
0x81, 0x03, // Input (Constant)
397+
#endif
398+
387399
// Keycodes (6 bytes)
388400
0x05, 0x07, // Usage Page (Keyboard/Keypad)
389401
0x19, 0x00, // Usage Minimum (0)

0 commit comments

Comments
 (0)