5

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.

Pep
  • 1,957
  • 2
  • 24
  • 40
  • In your program or on your computer? What language are you using? – Emil Vikström Feb 21 '13 at 17:19
  • My first use will be to try if I can put that virtual key in CoRD emulation program tables, as this is a need related to Windows programs accessed via CoRD. If that does not work, then I will probably try something with Objective C or C++ (I suppose that the Carbon framework will be involved). – Pep Feb 21 '13 at 17:49

2 Answers2

1

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.

AlwaysLearning
  • 7,915
  • 5
  • 27
  • 35
0

I know that question has been made years ago, but maybe some people are still looking for that answer and will end up finding that question so...

Line 1805 of VoodooPS2Keyboard.cpp from VoodooPS2Controller by RehabMan says that the virtual key on Mac for the Eject Key is 0x92.

Reference:

https://github.com/RehabMan/OS-X-Voodoo-PS2-Controller/blob/master/VoodooPS2Keyboard/VoodooPS2Keyboard.cpp

VitorMM
  • 1,060
  • 8
  • 33