I would like to remap the Mac Eject Key into Insert, in particular for emulating Ctrl+Insert, Alt+Insert, Shift+Insert and other common key combinations in Windows applications.
Which is the Virtual Key code for the Eject Key? I found some virtual key tables, but for some reason the Eject Key is never included.
Q: Which is the Virtual Key in Mac for the Eject Key?
A: None.
With reference to HID Usage Tables for Universal Serial Bus, Eject is not a keypress but actually a HID Usage - a One Shot Control from the Consumer Usage Page.
3.4.1.4 One Shot Control (OSC)
A One Shot Control is a push button that triggers a single event or action. A One Shot Control is encoded into a 1-bit value and declared as a Relative, Preferred, Main item with a Logical Minimum and Logical Maximum of 0 and 1, respectively. A 0 to 1 transition initiates an event. Nothing occurs on a 1 to 0 transition but it is required before another event can occur. An example is degauss.
On the Consumer Usage Page (0x0C) the Eject Usage ID is defined as:
Usage ID | Usage Name | Usage Types | Section |
---|---|---|---|
B8 | Eject | OSC | 15.7 |
If you were wanting to fake an Eject keypress from a USB HID-capable Arduino, such as the Leonardo, you could do so with the following code which sends a Control-Shift-Eject to lock the screen...
// NicoHood's HID-Project
#include "HID-Project.h"
void setup() {
// Make pin 2 an input and turn on the pull-up resistor
// so it goes high unless connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
// Sends a clean report to the host.
// This is important on any Arduino type.
Consumer.begin();
}
void loop() {
// Control-Shift-Eject locks the screen
if (digitalRead(2) == LOW) {
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_SHIFT);
// This is a One Shot Command so doesn't need a "release"
Consumer.write(HID_CONSUMER_EJECT);
// Debounce
delay(100);
while (digitalRead(2) == LOW)
delay(100);
// Release Control-Shift keys
Keyboard.releaseAll();
}
}
As to reacting to an Eject keypress from Windows, unless it's raised as one of the Media Control-related WM_ events I expect you'll have to write a USB HID/ACPI driver that detects and raises the OSC itself.
There is Sample buttons in ACPI for device running Windows 10 desktop editions which demonstrates capturing some of the other OSCs from the Consumer page (such as Volume Increments/Decrements), you could probably expand upon this to include Eject.
Sorry I can't be of more help there, but hopefully this points you in the right direction.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With