]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtGopDxe/WinNtGopInput.c
UefiCpuPkg: Remove double \r
[mirror_edk2.git] / Nt32Pkg / WinNtGopDxe / WinNtGopInput.c
index ccf75f5fcee489300866d2f213c9670590d3ba08..2e11ac11440bc8944cddd65ad87306badb0fa650 100644 (file)
@@ -1,13 +1,7 @@
 /** @file\r
 \r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 Module Name:\r
 \r
@@ -42,14 +36,13 @@ Abstract:
 **/\r
 EFI_STATUS\r
 GopPrivateCreateQ (\r
-  IN  GOP_PRIVATE_DATA    *Private\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  IN  GOP_QUEUE_FIXED     *Queue\r
   )\r
 {\r
-  Private->WinNtThunk->InitializeCriticalSection (&Private->QCriticalSection);\r
-\r
-  Private->Queue.Front  = 0;\r
-  Private->Queue.Rear   = MAX_Q - 1;\r
-  Private->Queue.Count  = 0;\r
+  Private->WinNtThunk->InitializeCriticalSection (&Queue->Cs);\r
+  Queue->Front = 0;\r
+  Queue->Rear  = 0;\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -64,11 +57,13 @@ GopPrivateCreateQ (
 **/\r
 EFI_STATUS\r
 GopPrivateDestroyQ (\r
-  IN  GOP_PRIVATE_DATA    *Private\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  IN  GOP_QUEUE_FIXED     *Queue\r
   )\r
 {\r
-  Private->Queue.Count = 0;\r
-  Private->WinNtThunk->DeleteCriticalSection (&Private->QCriticalSection);\r
+  Queue->Front = 0;\r
+  Queue->Rear  = 0;\r
+  Private->WinNtThunk->DeleteCriticalSection (&Queue->Cs);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -85,22 +80,22 @@ GopPrivateDestroyQ (
 **/\r
 EFI_STATUS\r
 GopPrivateAddQ (\r
-  IN  GOP_PRIVATE_DATA    *Private,\r
-  IN  EFI_INPUT_KEY       Key\r
+  IN GOP_PRIVATE_DATA     *Private,\r
+  IN GOP_QUEUE_FIXED      *Queue,\r
+  IN EFI_KEY_DATA         *KeyData\r
   )\r
 {\r
-  Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
+  Private->WinNtThunk->EnterCriticalSection (&Queue->Cs);\r
 \r
-  if (Private->Queue.Count == MAX_Q) {\r
-    Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  if ((Queue->Rear + 1) % MAX_Q == Queue->Front) {\r
+    Private->WinNtThunk->LeaveCriticalSection (&Queue->Cs);\r
     return EFI_NOT_READY;\r
   }\r
 \r
-  Private->Queue.Rear                   = (Private->Queue.Rear + 1) % MAX_Q;\r
-  Private->Queue.Q[Private->Queue.Rear] = Key;\r
-  Private->Queue.Count++;\r
+  CopyMem (&Queue->Q[Queue->Rear], KeyData, sizeof (EFI_KEY_DATA));\r
+  Queue->Rear           = (Queue->Rear + 1) % MAX_Q;\r
 \r
-  Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  Private->WinNtThunk->LeaveCriticalSection (&Queue->Cs);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -118,21 +113,31 @@ GopPrivateAddQ (
 EFI_STATUS\r
 GopPrivateDeleteQ (\r
   IN  GOP_PRIVATE_DATA    *Private,\r
-  OUT EFI_INPUT_KEY       *Key\r
+  IN  GOP_QUEUE_FIXED     *Queue,\r
+  OUT EFI_KEY_DATA        *Key\r
   )\r
 {\r
-  Private->WinNtThunk->EnterCriticalSection (&Private->QCriticalSection);\r
+  Private->WinNtThunk->EnterCriticalSection (&Queue->Cs);\r
 \r
-  if (Private->Queue.Count == 0) {\r
-    Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  if (Queue->Front == Queue->Rear) {\r
+    Private->WinNtThunk->LeaveCriticalSection (&Queue->Cs);\r
     return EFI_NOT_READY;\r
   }\r
 \r
-  *Key                  = Private->Queue.Q[Private->Queue.Front];\r
-  Private->Queue.Front  = (Private->Queue.Front + 1) % MAX_Q;\r
-  Private->Queue.Count--;\r
+  CopyMem (Key, &Queue->Q[Queue->Front], sizeof (EFI_KEY_DATA));\r
+  Queue->Front  = (Queue->Front + 1) % MAX_Q;\r
 \r
-  Private->WinNtThunk->LeaveCriticalSection (&Private->QCriticalSection);\r
+  if (Key->Key.ScanCode == SCAN_NULL && Key->Key.UnicodeChar == CHAR_NULL) {\r
+    if (!Private->IsPartialKeySupport) {\r
+      //\r
+      // If partial keystrok is not enabled, don't return the partial keystroke.\r
+      //\r
+      Private->WinNtThunk->LeaveCriticalSection (&Queue->Cs);\r
+      ZeroMem (Key, sizeof (EFI_KEY_DATA));\r
+      return EFI_NOT_READY;\r
+    }\r
+  }\r
+  Private->WinNtThunk->LeaveCriticalSection (&Queue->Cs);\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -148,10 +153,10 @@ GopPrivateDeleteQ (
 **/\r
 EFI_STATUS\r
 GopPrivateCheckQ (\r
-  IN  GOP_PRIVATE_DATA    *Private\r
+  IN  GOP_QUEUE_FIXED     *Queue\r
   )\r
 {\r
-  if (Private->Queue.Count == 0) {\r
+  if (Queue->Front == Queue->Rear) {\r
     return EFI_NOT_READY;\r
   }\r
 \r
@@ -169,36 +174,36 @@ Routine Description:
 \r
 Arguments:\r
 \r
-  RegsiteredData    - A pointer to a buffer that is filled in with the keystroke \r
+  RegsiteredData    - A pointer to a buffer that is filled in with the keystroke\r
                       state data for the key that was registered.\r
-  InputData         - A pointer to a buffer that is filled in with the keystroke \r
+  InputData         - A pointer to a buffer that is filled in with the keystroke\r
                       state data for the key that was pressed.\r
 \r
 Returns:\r
   TRUE              - Key be pressed matches a registered key.\r
-  FLASE             - Match failed. \r
-  \r
+  FLASE             - Match failed.\r
+\r
 --*/\r
 {\r
   ASSERT (RegsiteredData != NULL && InputData != NULL);\r
-  \r
+\r
   if ((RegsiteredData->Key.ScanCode    != InputData->Key.ScanCode) ||\r
       (RegsiteredData->Key.UnicodeChar != InputData->Key.UnicodeChar)) {\r
-    return FALSE;  \r
-  }      \r
-  \r
+    return FALSE;\r
+  }\r
+\r
   //\r
   // Assume KeyShiftState/KeyToggleState = 0 in Registered key data means these state could be ignored.\r
   //\r
   if (RegsiteredData->KeyState.KeyShiftState != 0 &&\r
       RegsiteredData->KeyState.KeyShiftState != InputData->KeyState.KeyShiftState) {\r
-    return FALSE;    \r
-  }   \r
+    return FALSE;\r
+  }\r
   if (RegsiteredData->KeyState.KeyToggleState != 0 &&\r
       RegsiteredData->KeyState.KeyToggleState != InputData->KeyState.KeyToggleState) {\r
-    return FALSE;    \r
-  }     \r
-  \r
+    return FALSE;\r
+  }\r
+\r
   return TRUE;\r
 \r
 }\r
@@ -218,29 +223,156 @@ Routine Description:
 Arguments:\r
 \r
   Private       - The private structure of WinNt Gop device.\r
-  KeyData       - A pointer to a buffer that is filled in with the keystroke \r
+  KeyData       - A pointer to a buffer that is filled in with the keystroke\r
                   state data for the key that was pressed.\r
 \r
 Returns:\r
 \r
   EFI_SUCCESS   - The status light is updated successfully.\r
 \r
---*/  \r
-{ \r
+--*/\r
+{\r
   LIST_ENTRY                          *Link;\r
   WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY  *CurrentNotify;\r
-  \r
+\r
   for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
     CurrentNotify = CR (\r
-                      Link, \r
-                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY, \r
-                      NotifyEntry, \r
+                      Link,\r
+                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY,\r
+                      NotifyEntry,\r
                       WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r
                       );\r
-    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { \r
+    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
       CurrentNotify->KeyNotificationFn (KeyData);\r
     }\r
-  }    \r
+  }\r
+}\r
+\r
+VOID\r
+WinNtGopSimpleTextInTimerHandler (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  GOP_PRIVATE_DATA  *Private;\r
+  EFI_KEY_DATA      KeyData;\r
+\r
+  Private = (GOP_PRIVATE_DATA *)Context;\r
+  while (GopPrivateDeleteQ (Private, &Private->QueueForNotify, &KeyData) == EFI_SUCCESS) {\r
+    GopPrivateInvokeRegisteredFunction (Private, &KeyData);\r
+  }\r
+}\r
+\r
+/**\r
+  Initialize the key state.\r
+\r
+  @param  Private               The GOP_PRIVATE_DATA instance.\r
+  @param  KeyState              A pointer to receive the key state information.\r
+**/\r
+VOID\r
+InitializeKeyState (\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  IN  EFI_KEY_STATE       *KeyState\r
+  )\r
+{\r
+  KeyState->KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
+  KeyState->KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
+\r
+  //\r
+  // Record Key shift state and toggle state\r
+  //\r
+  if (Private->LeftCtrl) {\r
+    KeyState->KeyShiftState  |= EFI_LEFT_CONTROL_PRESSED;\r
+  }\r
+  if (Private->RightCtrl) {\r
+    KeyState->KeyShiftState  |= EFI_RIGHT_CONTROL_PRESSED;\r
+  }\r
+  if (Private->LeftAlt) {\r
+    KeyState->KeyShiftState  |= EFI_LEFT_ALT_PRESSED;\r
+  }\r
+  if (Private->RightAlt) {\r
+    KeyState->KeyShiftState  |= EFI_RIGHT_ALT_PRESSED;\r
+  }\r
+  if (Private->LeftShift) {\r
+    KeyState->KeyShiftState  |= EFI_LEFT_SHIFT_PRESSED;\r
+  }\r
+  if (Private->RightShift) {\r
+    KeyState->KeyShiftState  |= EFI_RIGHT_SHIFT_PRESSED;\r
+  }\r
+  if (Private->LeftLogo) {\r
+    KeyState->KeyShiftState  |= EFI_LEFT_LOGO_PRESSED;\r
+  }\r
+  if (Private->RightLogo) {\r
+    KeyState->KeyShiftState  |= EFI_RIGHT_LOGO_PRESSED;\r
+  }\r
+  if (Private->Menu) {\r
+    KeyState->KeyShiftState  |= EFI_MENU_KEY_PRESSED;\r
+  }\r
+  if (Private->SysReq) {\r
+    KeyState->KeyShiftState  |= EFI_SYS_REQ_PRESSED;\r
+  }\r
+  if (Private->CapsLock) {\r
+    KeyState->KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;\r
+  }\r
+  if (Private->NumLock) {\r
+    KeyState->KeyToggleState |= EFI_NUM_LOCK_ACTIVE;\r
+  }\r
+  if (Private->ScrollLock) {\r
+    KeyState->KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;\r
+  }\r
+  if (Private->IsPartialKeySupport) {\r
+    KeyState->KeyToggleState |= EFI_KEY_STATE_EXPOSED;\r
+  }\r
+}\r
+\r
+/**\r
+  TODO: Add function description\r
+\r
+  @param  Private               TODO: add argument description\r
+  @param  Key                   TODO: add argument description\r
+\r
+  @retval EFI_NOT_READY         TODO: Add description for return value\r
+  @retval EFI_SUCCESS           TODO: Add description for return value\r
+\r
+**/\r
+EFI_STATUS\r
+GopPrivateAddKey (\r
+  IN  GOP_PRIVATE_DATA    *Private,\r
+  IN  EFI_INPUT_KEY       Key\r
+  )\r
+{\r
+  EFI_KEY_DATA            KeyData;\r
+\r
+  KeyData.Key = Key;\r
+  InitializeKeyState (Private, &KeyData.KeyState);\r
+\r
+  //\r
+  // Convert Ctrl+[1-26] to Ctrl+[A-Z]\r
+  //\r
+  if ((Private->LeftCtrl || Private->RightCtrl) &&\r
+      (KeyData.Key.UnicodeChar >= 1) && (KeyData.Key.UnicodeChar <= 26)\r
+     ) {\r
+    if ((Private->LeftShift || Private->RightShift) == Private->CapsLock) {\r
+      KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar + L'a' - 1);\r
+    } else {\r
+      KeyData.Key.UnicodeChar = (CHAR16)(KeyData.Key.UnicodeChar + L'A' - 1);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Unmask the Shift bit for printable char\r
+  //\r
+  if (((KeyData.Key.UnicodeChar >= L'a') && (KeyData.Key.UnicodeChar <= L'z')) ||\r
+      ((KeyData.Key.UnicodeChar >= L'A') && (KeyData.Key.UnicodeChar <= L'Z'))\r
+     ) {\r
+    KeyData.KeyState.KeyShiftState &= ~(EFI_LEFT_SHIFT_PRESSED | EFI_RIGHT_SHIFT_PRESSED);\r
+  }\r
+\r
+  GopPrivateAddQ (Private, &Private->QueueForNotify, &KeyData);\r
+\r
+  GopPrivateAddQ (Private, &Private->QueueForRead, &KeyData);\r
+\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 EFI_STATUS\r
@@ -261,16 +393,16 @@ Returns:
 \r
   EFI_SUCCESS   - The status light is updated successfully.\r
 \r
---*/  \r
-{ \r
+--*/\r
+{\r
   //\r
-  // BUGBUG:Only SendInput/keybd_event function can toggle \r
+  // BUGBUG:Only SendInput/keybd_event function can toggle\r
   // NumLock, CapsLock and ScrollLock keys.\r
   // Neither of these functions is included in EFI_WIN_NT_THUNK_PROTOCOL.\r
   // Thus, return immediately without operation.\r
   //\r
   return EFI_SUCCESS;\r
-  \r
+\r
 }\r
 \r
 \r
@@ -294,7 +426,7 @@ Returns:
 \r
 --*/\r
 {\r
-  EFI_INPUT_KEY     Key;\r
+  EFI_KEY_DATA      KeyData;\r
   EFI_TPL           OldTpl;\r
 \r
   //\r
@@ -305,7 +437,9 @@ Returns:
   //\r
   // A reset is draining the Queue\r
   //\r
-  while (GopPrivateDeleteQ (Private, &Key) == EFI_SUCCESS)\r
+  while (GopPrivateDeleteQ (Private, &Private->QueueForRead, &KeyData) == EFI_SUCCESS)\r
+    ;\r
+  while (GopPrivateDeleteQ (Private, &Private->QueueForNotify, &KeyData) == EFI_SUCCESS)\r
     ;\r
 \r
   Private->LeftShift               = FALSE;\r
@@ -318,11 +452,12 @@ Returns:
   Private->RightLogo               = FALSE;\r
   Private->Menu                    = FALSE;\r
   Private->SysReq                  = FALSE;\r
-  \r
+\r
   Private->CapsLock                = FALSE;\r
   Private->NumLock                 = FALSE;\r
   Private->ScrollLock              = FALSE;\r
\r
+  Private->IsPartialKeySupport     = FALSE;\r
+\r
   Private->KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
   Private->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
 \r
@@ -342,25 +477,25 @@ GopPrivateReadKeyStrokeWorker (
 /*++\r
 \r
   Routine Description:\r
-    Reads the next keystroke from the input device. The WaitForKey Event can \r
+    Reads the next keystroke from the input device. The WaitForKey Event can\r
     be used to test for existance of a keystroke via WaitForEvent () call.\r
 \r
   Arguments:\r
     Private    - The private structure of WinNt Gop device.\r
-    KeyData    - A pointer to a buffer that is filled in with the keystroke \r
+    KeyData    - A pointer to a buffer that is filled in with the keystroke\r
                  state data for the key that was pressed.\r
 \r
   Returns:\r
     EFI_SUCCESS           - The keystroke information was returned.\r
     EFI_NOT_READY         - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR      - The keystroke information was not returned due to \r
+    EFI_DEVICE_ERROR      - The keystroke information was not returned due to\r
                             hardware errors.\r
-    EFI_INVALID_PARAMETER - KeyData is NULL.                        \r
+    EFI_INVALID_PARAMETER - KeyData is NULL.\r
 \r
 --*/\r
 {\r
   EFI_STATUS                      Status;\r
-  EFI_TPL                         OldTpl;  \r
+  EFI_TPL                         OldTpl;\r
 \r
   if (KeyData == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -371,70 +506,30 @@ GopPrivateReadKeyStrokeWorker (
   //\r
   OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  Status  = GopPrivateCheckQ (Private);\r
+  //\r
+  // Call hot key callback before telling caller there is a key available\r
+  //\r
+  WinNtGopSimpleTextInTimerHandler (NULL, Private);\r
+\r
+  ZeroMem (&KeyData->Key, sizeof (KeyData->Key));\r
+  InitializeKeyState (Private, &KeyData->KeyState);\r
+\r
+  Status  = GopPrivateCheckQ (&Private->QueueForRead);\r
   if (!EFI_ERROR (Status)) {\r
     //\r
     // If a Key press exists try and read it.\r
     //\r
-    Status = GopPrivateDeleteQ (Private, &KeyData->Key);\r
+    Status = GopPrivateDeleteQ (Private, &Private->QueueForRead, KeyData);\r
     if (!EFI_ERROR (Status)) {\r
       //\r
-      // Record Key shift state and toggle state\r
-      //      \r
-      if (Private->LeftCtrl) {\r
-        Private->KeyState.KeyShiftState  |= EFI_LEFT_CONTROL_PRESSED;\r
-      }                                    \r
-      if (Private->RightCtrl) {\r
-        Private->KeyState.KeyShiftState  |= EFI_RIGHT_CONTROL_PRESSED;\r
-      }                                    \r
-      if (Private->LeftAlt) {                \r
-        Private->KeyState.KeyShiftState  |= EFI_LEFT_ALT_PRESSED;\r
-      }                                    \r
-      if (Private->RightAlt) {                \r
-        Private->KeyState.KeyShiftState  |= EFI_RIGHT_ALT_PRESSED;\r
-      }                                      \r
-      if (Private->LeftShift) {          \r
-        Private->KeyState.KeyShiftState  |= EFI_LEFT_SHIFT_PRESSED;\r
-      }                                    \r
-      if (Private->RightShift) {         \r
-        Private->KeyState.KeyShiftState  |= EFI_RIGHT_SHIFT_PRESSED;\r
-      }                                    \r
-      if (Private->LeftLogo) {           \r
-        Private->KeyState.KeyShiftState  |= EFI_LEFT_LOGO_PRESSED;\r
-      }                                    \r
-      if (Private->RightLogo) {          \r
-        Private->KeyState.KeyShiftState  |= EFI_RIGHT_LOGO_PRESSED;\r
-      }                                    \r
-      if (Private->Menu) {               \r
-        Private->KeyState.KeyShiftState  |= EFI_MENU_KEY_PRESSED;\r
-      }                                    \r
-      if (Private->SysReq) {             \r
-        Private->KeyState.KeyShiftState  |= EFI_SYS_REQ_PRESSED;\r
-      }  \r
-      if (Private->CapsLock) {\r
-        Private->KeyState.KeyToggleState |= EFI_CAPS_LOCK_ACTIVE;\r
-      }\r
-      if (Private->NumLock) {\r
-        Private->KeyState.KeyToggleState |= EFI_NUM_LOCK_ACTIVE;\r
-      }\r
-      if (Private->ScrollLock) {\r
-        Private->KeyState.KeyToggleState |= EFI_SCROLL_LOCK_ACTIVE;\r
-      }\r
-      \r
-      KeyData->KeyState.KeyShiftState  = Private->KeyState.KeyShiftState;\r
-      KeyData->KeyState.KeyToggleState = Private->KeyState.KeyToggleState;\r
-      \r
-      Private->KeyState.KeyShiftState  = EFI_SHIFT_STATE_VALID;\r
-      Private->KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID;\r
-  \r
-      //\r
-      // Leave critical section and return\r
+      // If partial keystroke is not enabled, check whether it is value key. If not return\r
+      // EFI_NOT_READY.\r
       //\r
-      gBS->RestoreTPL (OldTpl);\r
-      \r
-      GopPrivateInvokeRegisteredFunction (Private, KeyData);\r
-      \r
-      return EFI_SUCCESS;\r
+      if (!Private->IsPartialKeySupport) {\r
+        if (KeyData->Key.ScanCode == SCAN_NULL && KeyData->Key.UnicodeChar == CHAR_NULL) {\r
+          Status = EFI_NOT_READY;\r
+        }\r
+      }\r
     }\r
   }\r
 \r
@@ -498,15 +593,32 @@ WinNtGopSimpleTextInReadKeyStroke (
   EFI_KEY_DATA      KeyData;\r
 \r
   Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);\r
-\r
-  Status = GopPrivateReadKeyStrokeWorker (Private, &KeyData);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));\r
-  \r
-  return EFI_SUCCESS;  \r
+  //\r
+  // Considering if the partial keystroke is enabled, there maybe a partial\r
+  // keystroke in the queue, so here skip the partial keystroke and get the\r
+  // next key from the queue\r
+  //\r
+  while (1) {\r
+    Status = GopPrivateReadKeyStrokeWorker (Private, &KeyData);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    if (KeyData.Key.ScanCode == SCAN_NULL && KeyData.Key.UnicodeChar == CHAR_NULL) {\r
+      continue;\r
+    }\r
+    //\r
+    // Convert Ctrl+[A-Z] to Ctrl+[1-26]\r
+    //\r
+    if ((KeyData.KeyState.KeyShiftState & (EFI_LEFT_CONTROL_PRESSED | EFI_RIGHT_CONTROL_PRESSED)) != 0) {\r
+      if ((KeyData.Key.UnicodeChar >= L'a') && (KeyData.Key.UnicodeChar <= L'z')) {\r
+        KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'a' + 1);\r
+      } else if ((KeyData.Key.UnicodeChar >= L'A') && (KeyData.Key.UnicodeChar <= L'Z')) {\r
+        KeyData.Key.UnicodeChar = (CHAR16) (KeyData.Key.UnicodeChar - L'A' + 1);\r
+      }\r
+    }\r
+    CopyMem (Key, &KeyData.Key, sizeof (EFI_INPUT_KEY));\r
+    return EFI_SUCCESS;\r
+  }  \r
 }\r
 \r
 \r
@@ -529,6 +641,7 @@ WinNtGopSimpleTextInWaitForKey (
   GOP_PRIVATE_DATA  *Private;\r
   EFI_STATUS        Status;\r
   EFI_TPL           OldTpl;\r
+  EFI_KEY_DATA      KeyData;\r
 \r
   Private = (GOP_PRIVATE_DATA *) Context;\r
 \r
@@ -537,20 +650,39 @@ WinNtGopSimpleTextInWaitForKey (
   //\r
   OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);\r
 \r
-  Status  = GopPrivateCheckQ (Private);\r
-  if (!EFI_ERROR (Status)) {\r
-    //\r
-    // If a there is a key in the queue signal our event.\r
-    //\r
-    gBS->SignalEvent (Event);\r
-  } else {\r
-    //\r
-    // We need to sleep or NT will schedule this thread with such high\r
-    // priority that WinProc thread will never run and we will not see\r
-    // keyboard input. This Sleep makes the syste run 10x faster, so don't\r
-    // remove it.\r
-    //\r
-    Private->WinNtThunk->Sleep (1);\r
+  //\r
+  // Call hot key callback before telling caller there is a key available\r
+  //\r
+  WinNtGopSimpleTextInTimerHandler (NULL, Private);\r
+  \r
+  //\r
+  // WaitforKey doesn't suppor the partial key.\r
+  // Considering if the partial keystroke is enabled, there maybe a partial\r
+  // keystroke in the queue, so here skip the partial keystroke and get the\r
+  // next key from the queue\r
+  //\r
+  while (1) {\r
+    Status  = GopPrivateCheckQ (&Private->QueueForRead);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // If a there is a key in the queue and it is not partial keystroke,  signal event.\r
+      //\r
+      if (Private->QueueForRead.Q[Private->QueueForRead.Front].Key.ScanCode == SCAN_NULL &&\r
+        Private->QueueForRead.Q[Private->QueueForRead.Front].Key.UnicodeChar == CHAR_NULL) {\r
+        GopPrivateDeleteQ (Private,&Private->QueueForRead,&KeyData);\r
+        continue;\r
+      }\r
+      gBS->SignalEvent (Event);\r
+    } else {\r
+      //\r
+      // We need to sleep or NT will schedule this thread with such high\r
+      // priority that WinProc thread will never run and we will not see\r
+      // keyboard input. This Sleep makes the syste run 10x faster, so don't\r
+      // remove it.\r
+      //\r
+      Private->WinNtThunk->Sleep (1);\r
+    }\r
+    break;\r
   }\r
 \r
   //\r
@@ -586,7 +718,7 @@ WinNtGopSimpleTextInExResetEx (
   GOP_PRIVATE_DATA *Private;\r
 \r
   Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);\r
-  \r
+\r
   return GopPrivateResetWorker (Private);\r
 }\r
 \r
@@ -599,20 +731,20 @@ WinNtGopSimpleTextInExReadKeyStrokeEx (
 /*++\r
 \r
   Routine Description:\r
-    Reads the next keystroke from the input device. The WaitForKey Event can \r
+    Reads the next keystroke from the input device. The WaitForKey Event can\r
     be used to test for existance of a keystroke via WaitForEvent () call.\r
 \r
   Arguments:\r
     This       - Protocol instance pointer.\r
-    KeyData    - A pointer to a buffer that is filled in with the keystroke \r
+    KeyData    - A pointer to a buffer that is filled in with the keystroke\r
                  state data for the key that was pressed.\r
 \r
   Returns:\r
     EFI_SUCCESS           - The keystroke information was returned.\r
     EFI_NOT_READY         - There was no keystroke data availiable.\r
-    EFI_DEVICE_ERROR      - The keystroke information was not returned due to \r
+    EFI_DEVICE_ERROR      - The keystroke information was not returned due to\r
                             hardware errors.\r
-    EFI_INVALID_PARAMETER - KeyData is NULL.                        \r
+    EFI_INVALID_PARAMETER - KeyData is NULL.\r
 \r
 --*/\r
 {\r
@@ -623,7 +755,7 @@ WinNtGopSimpleTextInExReadKeyStrokeEx (
   }\r
 \r
   Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);\r
-  \r
+\r
   return GopPrivateReadKeyStrokeWorker (Private, KeyData);\r
 \r
 }\r
@@ -641,17 +773,17 @@ WinNtGopSimpleTextInExSetState (
 \r
   Arguments:\r
     This                  - Protocol instance pointer.\r
-    KeyToggleState        - A pointer to the EFI_KEY_TOGGLE_STATE to set the \r
+    KeyToggleState        - A pointer to the EFI_KEY_TOGGLE_STATE to set the\r
                             state for the input device.\r
-                          \r
-  Returns:                \r
+\r
+  Returns:\r
     EFI_SUCCESS           - The device state was set successfully.\r
-    EFI_DEVICE_ERROR      - The device is not functioning correctly and could \r
+    EFI_DEVICE_ERROR      - The device is not functioning correctly and could\r
                             not have the setting adjusted.\r
     EFI_UNSUPPORTED       - The device does not have the ability to set its state.\r
-    EFI_INVALID_PARAMETER - KeyToggleState is NULL.                       \r
+    EFI_INVALID_PARAMETER - KeyToggleState is NULL.\r
 \r
---*/   \r
+--*/\r
 {\r
   EFI_STATUS                      Status;\r
   GOP_PRIVATE_DATA                *Private;\r
@@ -664,31 +796,35 @@ WinNtGopSimpleTextInExSetState (
 \r
   if (((Private->KeyState.KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID) ||\r
       ((*KeyToggleState & EFI_TOGGLE_STATE_VALID) != EFI_TOGGLE_STATE_VALID)) {\r
-    return EFI_UNSUPPORTED;  \r
+    return EFI_UNSUPPORTED;\r
   }\r
 \r
-  Private->ScrollLock = FALSE;\r
-  Private->NumLock    = FALSE;\r
-  Private->CapsLock   = FALSE;\r
+  Private->ScrollLock          = FALSE;\r
+  Private->NumLock             = FALSE;\r
+  Private->CapsLock            = FALSE;\r
+  Private->IsPartialKeySupport = FALSE;\r
 \r
   if ((*KeyToggleState & EFI_SCROLL_LOCK_ACTIVE) == EFI_SCROLL_LOCK_ACTIVE) {\r
     Private->ScrollLock = TRUE;\r
-  } \r
+  }\r
   if ((*KeyToggleState & EFI_NUM_LOCK_ACTIVE) == EFI_NUM_LOCK_ACTIVE) {\r
     Private->NumLock = TRUE;\r
   }\r
   if ((*KeyToggleState & EFI_CAPS_LOCK_ACTIVE) == EFI_CAPS_LOCK_ACTIVE) {\r
     Private->CapsLock = TRUE;\r
   }\r
+  if ((*KeyToggleState & EFI_KEY_STATE_EXPOSED) == EFI_KEY_STATE_EXPOSED) {\r
+    Private->IsPartialKeySupport = TRUE;\r
+  }\r
 \r
-  Status = GopPrivateUpdateStatusLight (Private);  \r
+  Status = GopPrivateUpdateStatusLight (Private);\r
   if (EFI_ERROR (Status)) {\r
     return EFI_DEVICE_ERROR;\r
   }\r
 \r
   Private->KeyState.KeyToggleState = *KeyToggleState;\r
   return EFI_SUCCESS;\r
-  \r
+\r
 }\r
 \r
 EFI_STATUS\r
@@ -697,7 +833,7 @@ WinNtGopSimpleTextInExRegisterKeyNotify (
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
   IN EFI_KEY_DATA                       *KeyData,\r
   IN EFI_KEY_NOTIFY_FUNCTION            KeyNotificationFunction,\r
-  OUT EFI_HANDLE                        *NotifyHandle\r
+  OUT VOID                              **NotifyHandle\r
   )\r
 /*++\r
 \r
@@ -706,23 +842,23 @@ WinNtGopSimpleTextInExRegisterKeyNotify (
 \r
   Arguments:\r
     This                    - Protocol instance pointer.\r
-    KeyData                 - A pointer to a buffer that is filled in with the keystroke \r
+    KeyData                 - A pointer to a buffer that is filled in with the keystroke\r
                               information data for the key that was pressed.\r
-    KeyNotificationFunction - Points to the function to be called when the key \r
-                              sequence is typed specified by KeyData.                        \r
-    NotifyHandle            - Points to the unique handle assigned to the registered notification.                          \r
+    KeyNotificationFunction - Points to the function to be called when the key\r
+                              sequence is typed specified by KeyData.\r
+    NotifyHandle            - Points to the unique handle assigned to the registered notification.\r
 \r
   Returns:\r
     EFI_SUCCESS             - The notification function was registered successfully.\r
     EFI_OUT_OF_RESOURCES    - Unable to allocate resources for necesssary data structures.\r
-    EFI_INVALID_PARAMETER   - KeyData or NotifyHandle is NULL.                       \r
-                              \r
---*/   \r
+    EFI_INVALID_PARAMETER   - KeyData or NotifyHandle is NULL.\r
+\r
+--*/\r
 {\r
   GOP_PRIVATE_DATA                   *Private;\r
   WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *CurrentNotify;\r
   LIST_ENTRY                         *Link;\r
-  WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify;      \r
+  WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *NewNotify;\r
 \r
   if (KeyData == NULL || KeyNotificationFunction == NULL || NotifyHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -735,44 +871,43 @@ WinNtGopSimpleTextInExRegisterKeyNotify (
   //\r
   for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
     CurrentNotify = CR (\r
-                      Link, \r
-                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY, \r
-                      NotifyEntry, \r
+                      Link,\r
+                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY,\r
+                      NotifyEntry,\r
                       WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r
                       );\r
-    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) { \r
+    if (GopPrivateIsKeyRegistered (&CurrentNotify->KeyData, KeyData)) {\r
       if (CurrentNotify->KeyNotificationFn == KeyNotificationFunction) {\r
-        *NotifyHandle = CurrentNotify->NotifyHandle;\r
+        *NotifyHandle = CurrentNotify;\r
         return EFI_SUCCESS;\r
       }\r
     }\r
-  }    \r
-  \r
+  }\r
+\r
   //\r
   // Allocate resource to save the notification function\r
-  //  \r
+  //\r
   NewNotify = (WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) AllocateZeroPool (sizeof (WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY));\r
   if (NewNotify == NULL) {\r
     return EFI_OUT_OF_RESOURCES;\r
   }\r
 \r
-  NewNotify->Signature         = WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;     \r
+  NewNotify->Signature         = WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE;\r
   NewNotify->KeyNotificationFn = KeyNotificationFunction;\r
-  NewNotify->NotifyHandle      = (EFI_HANDLE) NewNotify;\r
-  CopyMem (&NewNotify->KeyData, KeyData, sizeof (KeyData));\r
+  CopyMem (&NewNotify->KeyData, KeyData, sizeof (EFI_KEY_DATA));\r
   InsertTailList (&Private->NotifyList, &NewNotify->NotifyEntry);\r
 \r
-  *NotifyHandle = NewNotify->NotifyHandle;  \r
-  \r
+  *NotifyHandle = NewNotify;\r
+\r
   return EFI_SUCCESS;\r
-  \r
+\r
 }\r
 \r
 EFI_STATUS\r
 EFIAPI\r
 WinNtGopSimpleTextInExUnregisterKeyNotify (\r
   IN EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL  *This,\r
-  IN EFI_HANDLE                         NotificationHandle\r
+  IN VOID                               *NotificationHandle\r
   )\r
 /*++\r
 \r
@@ -780,14 +915,14 @@ WinNtGopSimpleTextInExUnregisterKeyNotify (
     Remove a registered notification function from a particular keystroke.\r
 \r
   Arguments:\r
-    This                    - Protocol instance pointer.    \r
+    This                    - Protocol instance pointer.\r
     NotificationHandle      - The handle of the notification function being unregistered.\r
 \r
   Returns:\r
     EFI_SUCCESS             - The notification function was unregistered successfully.\r
     EFI_INVALID_PARAMETER   - The NotificationHandle is invalid.\r
-                              \r
---*/   \r
+\r
+--*/\r
 {\r
   GOP_PRIVATE_DATA                   *Private;\r
   LIST_ENTRY                         *Link;\r
@@ -795,28 +930,24 @@ WinNtGopSimpleTextInExUnregisterKeyNotify (
 \r
   if (NotificationHandle == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
-  } \r
-\r
-  if (((WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY *) NotificationHandle)->Signature != WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE) {\r
-    return EFI_INVALID_PARAMETER;\r
-  } \r
+  }\r
 \r
   Private = GOP_PRIVATE_DATA_FROM_TEXT_IN_EX_THIS (This);\r
 \r
   for (Link = Private->NotifyList.ForwardLink; Link != &Private->NotifyList; Link = Link->ForwardLink) {\r
     CurrentNotify = CR (\r
-                      Link, \r
-                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY, \r
-                      NotifyEntry, \r
+                      Link,\r
+                      WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY,\r
+                      NotifyEntry,\r
                       WIN_NT_GOP_SIMPLE_TEXTIN_EX_NOTIFY_SIGNATURE\r
-                      );       \r
-    if (CurrentNotify->NotifyHandle == NotificationHandle) {\r
+                      );\r
+    if (CurrentNotify == NotificationHandle) {\r
       //\r
       // Remove the notification function from NotifyList and free resources\r
       //\r
-      RemoveEntryList (&CurrentNotify->NotifyEntry);      \r
+      RemoveEntryList (&CurrentNotify->NotifyEntry);\r
 \r
-      gBS->FreePool (CurrentNotify);            \r
+      gBS->FreePool (CurrentNotify);\r
       return EFI_SUCCESS;\r
     }\r
   }\r
@@ -827,6 +958,7 @@ WinNtGopSimpleTextInExUnregisterKeyNotify (
   return EFI_INVALID_PARAMETER;\r
 }\r
 \r
+\r
 /**\r
   TODO: Add function description\r
 \r
@@ -842,7 +974,8 @@ WinNtGopInitializeSimpleTextInForWindow (
 {\r
   EFI_STATUS  Status;\r
 \r
-  GopPrivateCreateQ (Private);\r
+  GopPrivateCreateQ (Private, &Private->QueueForRead);\r
+  GopPrivateCreateQ (Private, &Private->QueueForNotify);\r
 \r
   //\r
   // Initialize Simple Text In protoocol\r
@@ -858,7 +991,7 @@ WinNtGopInitializeSimpleTextInForWindow (
                   &Private->SimpleTextIn.WaitForKey\r
                   );\r
 \r
-  \r
+\r
   Private->SimpleTextInEx.Reset               = WinNtGopSimpleTextInExResetEx;\r
   Private->SimpleTextInEx.ReadKeyStrokeEx     = WinNtGopSimpleTextInExReadKeyStrokeEx;\r
   Private->SimpleTextInEx.SetState            = WinNtGopSimpleTextInExSetState;\r
@@ -866,7 +999,7 @@ WinNtGopInitializeSimpleTextInForWindow (
   Private->SimpleTextInEx.UnregisterKeyNotify = WinNtGopSimpleTextInExUnregisterKeyNotify;\r
 \r
   Private->SimpleTextInEx.Reset (&Private->SimpleTextInEx, FALSE);\r
-  \r
+\r
   InitializeListHead (&Private->NotifyList);\r
 \r
   Status = gBS->CreateEvent (\r
@@ -878,6 +1011,24 @@ WinNtGopInitializeSimpleTextInForWindow (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Create the Timer to trigger hot key notifications\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
+                  TPL_NOTIFY,\r
+                  WinNtGopSimpleTextInTimerHandler,\r
+                  Private,\r
+                  &Private->TimerEvent\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = gBS->SetTimer (\r
+                  Private->TimerEvent,\r
+                  TimerPeriodic,\r
+                  KEYBOARD_TIMER_INTERVAL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
 \r
   return Status;\r
 }\r
@@ -897,6 +1048,10 @@ WinNtGopDestroySimpleTextInForWindow (
   IN  GOP_PRIVATE_DATA    *Private\r
   )\r
 {\r
-  GopPrivateDestroyQ (Private);\r
+  gBS->CloseEvent (Private->TimerEvent);\r
+\r
+  GopPrivateDestroyQ (Private, &Private->QueueForRead);\r
+  GopPrivateDestroyQ (Private, &Private->QueueForNotify);\r
+\r
   return EFI_SUCCESS;\r
 }\r