27#include <Library/BaseMemoryLib.h>
28#include <Library/DebugLib.h>
29#include <Library/MemoryAllocationLib.h>
30#include <Library/UefiBootServicesTableLib.h>
31#include <Library/UefiLib.h>
36#define KEY_STROKE_DELAY 5
39#define KEY_STROKE_POLL_FREQUENCY EFI_TIMER_PERIOD_MILLISECONDS (10)
84 IN BOOLEAN CustomDelays,
85 IN UINT16 KeyInitialDelay,
86 IN UINT16 KeySubsequentDelay,
87 IN BOOLEAN GraphicsInputMirroring
99 if (KeySubsequentDelay == 0) {
100 KeySubsequentDelay = 1;
101 DEBUG ((DEBUG_WARN,
"OCAE: Illegal KeySubsequentDelay value 0, using 1\n"));
117 OUT UINTN *NumberOfKeyCodes,
123 DEBUG ((DEBUG_VERBOSE,
"InternalGetAppleKeyStrokes\n"));
125 Status = EFI_UNSUPPORTED;
128 Status = EFI_INVALID_PARAMETER;
130 if ( (Modifiers != NULL)
131 && (NumberOfKeyCodes != NULL)
132 && (KeyCodes != NULL))
134 *NumberOfKeyCodes = 0;
143 if (!EFI_ERROR (Status) || (Status == EFI_BUFFER_TOO_SMALL)) {
144 if (*NumberOfKeyCodes == 0) {
147 *KeyCodes = AllocateZeroPool (
148 *NumberOfKeyCodes *
sizeof (**KeyCodes)
151 if (*KeyCodes == NULL) {
152 *NumberOfKeyCodes = 0;
153 Status = EFI_OUT_OF_RESOURCES;
154 DEBUG ((DEBUG_VERBOSE,
"InternalGetAppleKeyStrokes alloc failure\n"));
163 if (EFI_ERROR (Status)) {
164 FreePool ((VOID *)*KeyCodes);
167 *NumberOfKeyCodes = 0;
186 UINTN NumberOfKeyCodes;
189 DEBUG ((DEBUG_VERBOSE,
"InternalGetModifierStrokes\n"));
197 if (!EFI_ERROR (Status)) {
198 if (KeyCodes != NULL) {
199 FreePool ((VOID *)KeyCodes);
214 IN EFI_INPUT_KEY *InputKey
220 DEBUG ((DEBUG_VERBOSE,
"InternalAppleKeyEventDataFromInputKey\n"));
222 Status = EFI_INVALID_PARAMETER;
224 if ((EventData != NULL) && (
AppleKeyCode != NULL) && (InputKey != NULL)) {
225 KeyEventData = AllocateZeroPool (
sizeof (*KeyEventData));
226 Status = EFI_OUT_OF_RESOURCES;
228 if (KeyEventData != NULL) {
238 EventData->KeyData = KeyEventData;
240 Status = EFI_SUCCESS;
251 IN CONST UINTN *NumberOfKeyCodes,
256 UINTN NumberOfReleasedKeys;
260 UINTN ReleasedKeysSize;
262 DEBUG ((DEBUG_VERBOSE,
"InternalGetAndRemoveReleasedKeys\n"));
264 NumberOfReleasedKeys = 0;
267 for (Index2 = 0; Index2 < *NumberOfKeyCodes; ++Index2) {
273 if (*NumberOfKeyCodes == Index2) {
276 ++NumberOfReleasedKeys;
289 for (Index = 0; Index < *NumberOfKeyCodes; ++Index) {
295 if (*NumberOfKeyCodes == Index) {
299 ++NumberOfReleasedKeys;
305 *ReleasedKeys = NULL;
307 if (NumberOfReleasedKeys > 0) {
308 ReleasedKeysSize = (
sizeof (**ReleasedKeys) * NumberOfReleasedKeys);
309 *ReleasedKeys = AllocateZeroPool (ReleasedKeysSize);
311 if (*ReleasedKeys != NULL) {
313 (VOID *)*ReleasedKeys,
314 (VOID *)&ReleasedKeysBuffer[0],
318 NumberOfReleasedKeys = 0;
322 return NumberOfReleasedKeys;
329 IN CONST UINTN *NumberOfKeyCodes,
338 DEBUG ((DEBUG_VERBOSE,
"InternalIsCLockOn\n"));
343 if ( (NumberOfKeyCodes == NULL)
344 || ((*NumberOfKeyCodes != 0) && (KeyCodes == NULL)))
354 for (Index = 0; Index < *NumberOfKeyCodes; ++Index) {
364 if ( (KeyInfo == NULL)
368 CLockOn = (BOOLEAN)
mCLockOn == FALSE;
386 DEBUG ((DEBUG_VERBOSE,
"InternalGetCurrentStroke\n"));
405 IN OUT UINTN *NumberOfKeyCodes,
407 IN OUT EFI_INPUT_KEY *Key
413 UINTN NumberOfReleasedKeys;
417 BOOLEAN ShiftPressed;
418 EFI_INPUT_KEY InputKey;
421 BOOLEAN AcceptStroke;
424 DEBUG ((DEBUG_VERBOSE,
"InternalGetCurrentKeyStroke\n"));
440 AppleModifiers = Modifiers;
448 for (Index = 0; Index < NumberOfReleasedKeys; ++Index) {
458 &ReleasedKeys[Index],
462 if (EFI_ERROR (Status)) {
473 if (ReleasedKeys != NULL) {
474 FreePool ((VOID *)ReleasedKeys);
485 for (NewKeyIndex = 0; NewKeyIndex < *NumberOfKeyCodes; ++NewKeyIndex) {
499 if (KeyInfo == NULL) {
527 Status = EFI_NOT_READY;
529 if ((KeyInfo != NULL) || (
mModifiers != Modifiers)) {
536 if (KeyInfo != NULL) {
537 AcceptStroke = (BOOLEAN)(
544 *NumberOfKeyCodes = 1;
558 Status = EFI_SUCCESS;
564 *NumberOfKeyCodes = 0;
565 Status = EFI_SUCCESS;
581 EFI_INPUT_KEY InputKey;
584 UINTN NumberOfKeyCodes;
589 DEBUG ((DEBUG_VERBOSE,
"InternalAppleEventDataFromCurrentKeyStroke\n"));
591 ZeroMem (&InputKey,
sizeof (InputKey));
595 Status = EFI_UNSUPPORTED;
598 && (EventData != NULL)
599 && (Modifiers != NULL))
602 NumberOfKeyCodes = 0;
620 Status =
gBS->LocateProtocol (
623 (VOID *)&ConsoleControl
626 if (!EFI_ERROR (Status)) {
627 ConsoleControl->GetMode (ConsoleControl, &Mode, NULL, NULL);
631 for (Index = 0; Index < (NumberOfKeyCodes + 1); ++Index) {
632 Status =
gST->ConIn->ReadKeyStroke (
gST->ConIn, &InputKey);
634 if (EFI_ERROR (Status)) {
641 *Modifiers = AppleModifiers;
649 if (!EFI_ERROR (Status)) {
650 Status = EFI_SUCCESS;
651 if (NumberOfKeyCodes > 0) {
678 DEBUG ((DEBUG_VERBOSE,
"InternalKeyStrokePollNotifyFunction\n"));
687 if (!EFI_ERROR (Status)) {
688 if (EventData.
KeyData != NULL) {
695 if (PartialModifers != 0) {
707 if (PartialModifers != 0) {
729 DEBUG ((DEBUG_VERBOSE,
"InternalInitializeKeyHandler\n"));
750 DEBUG ((DEBUG_VERBOSE,
"EventCreateKeyStrokePollEvent\n"));
752 Status =
gBS->LocateProtocol (
758 if (!EFI_ERROR (Status)) {
769 ? EFI_OUT_OF_RESOURCES
782 DEBUG ((DEBUG_VERBOSE,
"EventCancelKeyStrokePollEvent\n"));
803 IN OUT BOOLEAN *CLockOn
808 DEBUG ((DEBUG_VERBOSE,
"EventIsCapsLockOnImpl\n"));
810 Status = EFI_INVALID_PARAMETER;
812 if (CLockOn != NULL) {
815 Status = EFI_SUCCESS;
#define APPLE_EVENT_TYPE_MODIFIER_UP
#define APPLE_EVENT_TYPE_KEY_DOWN
#define APPLE_EVENT_TYPE_MODIFIER_DOWN
#define APPLE_EVENT_TYPE_KEY_UP
VOID EventInputKeyFromAppleKeyCode(IN APPLE_KEY_CODE AppleKeyCode, OUT EFI_INPUT_KEY *InputKey, IN BOOLEAN Shifted)
EFI_STATUS EventCreateEventQueue(IN APPLE_EVENT_DATA EventData, IN APPLE_EVENT_TYPE EventType, IN APPLE_MODIFIER_MAP Modifiers)
EFI_EVENT EventLibCreateNotifyTimerEvent(IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext, IN UINT64 TriggerTime, IN BOOLEAN SignalPeriodic)
VOID EventLibCancelEvent(IN EFI_EVENT Event)
@ AppleHidUsbKbUsageKeyCLock
#define IS_APPLE_KEY_LETTER(Usage)
APPLE_HID_USAGE APPLE_KEY_CODE
UINT16 APPLE_MODIFIER_MAP
#define APPLE_MODIFIERS_SHIFT
EFI_GUID gAppleKeyMapAggregatorProtocolGuid
#define ARRAY_SIZE(Array)
EFI_CONSOLE_CONTROL_SCREEN_MODE
@ EfiConsoleControlScreenGraphics
EFI_GUID gEfiConsoleControlProtocolGuid
EFI_STATUS EFIAPI EventIsCapsLockOnImpl(IN OUT BOOLEAN *CLockOn)
VOID InternalSetKeyBehaviour(IN BOOLEAN CustomDelays, IN UINT16 KeyInitialDelay, IN UINT16 KeySubsequentDelay, IN BOOLEAN GraphicsInputMirroring)
STATIC BOOLEAN mGraphicsInputMirroring
STATIC APPLE_MODIFIER_MAP mPreviousModifiers
STATIC UINTN mKeySubsequentDelay
STATIC UINTN InternalGetAndRemoveReleasedKeys(IN CONST UINTN *NumberOfKeyCodes, IN CONST APPLE_KEY_CODE *KeyCodes, OUT APPLE_KEY_CODE **ReleasedKeys)
STATIC BOOLEAN InternalIsCLockOn(IN CONST UINTN *NumberOfKeyCodes, IN CONST APPLE_KEY_CODE *KeyCodes)
STATIC KEY_STROKE_INFORMATION * InternalGetCurrentStroke(VOID)
STATIC EFI_STATUS InternalGetAppleKeyStrokes(OUT APPLE_MODIFIER_MAP *Modifiers, OUT UINTN *NumberOfKeyCodes, OUT APPLE_KEY_CODE **KeyCodes)
STATIC EFI_STATUS InternalAppleKeyEventDataFromInputKey(OUT APPLE_EVENT_DATA *EventData, IN APPLE_KEY_CODE *AppleKeyCode, IN EFI_INPUT_KEY *InputKey)
#define KEY_STROKE_POLL_FREQUENCY
STATIC APPLE_KEY_MAP_AGGREGATOR_PROTOCOL * mKeyMapAggregator
STATIC EFI_STATUS InternalAppleEventDataFromCurrentKeyStroke(IN OUT APPLE_EVENT_DATA *EventData, IN OUT APPLE_MODIFIER_MAP *Modifiers)
STATIC EFI_EVENT mKeyStrokePollEvent
STATIC BOOLEAN mCLockChanged
VOID EventCancelKeyStrokePollEvent(VOID)
EFI_STATUS EventCreateKeyStrokePollEvent(VOID)
STATIC UINTN mKeyInitialDelay
STATIC EFI_STATUS InternalGetCurrentKeyStroke(IN APPLE_MODIFIER_MAP Modifiers, IN OUT UINTN *NumberOfKeyCodes, IN OUT APPLE_KEY_CODE *KeyCodes, IN OUT EFI_INPUT_KEY *Key)
STATIC APPLE_MODIFIER_MAP mModifiers
STATIC BOOLEAN mInitialized
STATIC VOID InternalInitializeKeyHandler(VOID)
STATIC KEY_STROKE_INFORMATION mKeyStrokeInfo[10]
STATIC VOID EFIAPI InternalKeyStrokePollNotifyFunction(IN EFI_EVENT Event, IN VOID *Context)
APPLE_MODIFIER_MAP InternalGetModifierStrokes(VOID)
APPLE_KEY_CODE AppleKeyCode
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
APPLE_KEY_CODE AppleKeyCode
KEY_MAP_GET_KEY_STROKES GetKeyStrokes
APPLE_KEY_CODE AppleKeyCode
APPLE_KEY_EVENT_DATA * KeyData