3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Console based on Win32 APIs.
20 This file attaches a SimpleTextIn protocol to a previously open window.
22 The constructor for this protocol depends on an open window. Currently
23 the SimpleTextOut protocol creates a window when it's constructor is called.
24 Thus this code must run after the constructor for the SimpleTextOut
29 // The package level header files this module uses
34 // The protocols, PPI and GUID defintions for this module
36 #include <Protocol/SimpleTextIn.h>
37 #include <Protocol/WinNtIo.h>
38 #include <Protocol/SimpleTextOut.h>
39 #include <Protocol/ComponentName.h>
40 #include <Protocol/DriverBinding.h>
42 // The Library classes this module consumes
44 #include <Library/DebugLib.h>
45 #include <Library/BaseLib.h>
46 #include <Library/UefiDriverEntryPoint.h>
47 #include <Library/UefiLib.h>
48 #include <Library/BaseMemoryLib.h>
49 #include <Library/UefiBootServicesTableLib.h>
50 #include <Library/MemoryAllocationLib.h>
54 // Private worker functions
58 WinNtSimpleTextInCheckKey (
59 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
64 WinNtSimpleTextInReset (
65 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
66 IN BOOLEAN ExtendedVerification
72 TODO: Add function description
76 This - TODO: add argument description
77 ExtendedVerification - TODO: add argument description
81 EFI_SUCCESS - TODO: Add description for return value
85 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
87 Private
= WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This
);
93 WinNtConvertInputRecordToEfiKey (
94 IN INPUT_RECORD
*InputRecord
,
95 OUT EFI_INPUT_KEY
*Key
101 TODO: Add function description
105 InputRecord - TODO: add argument description
106 Key - TODO: add argument description
110 EFI_NOT_READY - TODO: Add description for return value
111 EFI_NOT_READY - TODO: Add description for return value
112 EFI_NOT_READY - TODO: Add description for return value
113 EFI_SUCCESS - TODO: Add description for return value
118 // Make sure InputRecord is an event that represents a keypress
120 if (InputRecord
->EventType
== KEY_EVENT
) {
121 if (!InputRecord
->Event
.KeyEvent
.bKeyDown
) {
122 return EFI_NOT_READY
;
125 return EFI_NOT_READY
;
129 // Check to see if we should return a scan code in place of Unicode character.
132 Key
->UnicodeChar
= 0;
133 if ((InputRecord
->Event
.KeyEvent
.dwControlKeyState
& (NUMLOCK_ON
| ENHANCED_KEY
)) != NUMLOCK_ON
) {
135 // Only check these scan codes if num lock is off.
137 switch (InputRecord
->Event
.KeyEvent
.wVirtualScanCode
) {
138 case 0x48: Key
->ScanCode
= SCAN_UP
; break;
139 case 0x50: Key
->ScanCode
= SCAN_DOWN
; break;
140 case 0x4d: Key
->ScanCode
= SCAN_RIGHT
; break;
141 case 0x4b: Key
->ScanCode
= SCAN_LEFT
; break;
142 case 0x47: Key
->ScanCode
= SCAN_HOME
; break;
143 case 0x4F: Key
->ScanCode
= SCAN_END
; break;
144 case 0x52: Key
->ScanCode
= SCAN_INSERT
; break;
145 case 0x53: Key
->ScanCode
= SCAN_DELETE
; break;
146 case 0x49: Key
->ScanCode
= SCAN_PAGE_UP
; break;
147 case 0x51: Key
->ScanCode
= SCAN_PAGE_DOWN
; break;
151 switch (InputRecord
->Event
.KeyEvent
.wVirtualScanCode
) {
152 case 0x3b: Key
->ScanCode
= SCAN_F1
; break;
153 case 0x3c: Key
->ScanCode
= SCAN_F2
; break;
154 case 0x3d: Key
->ScanCode
= SCAN_F3
; break;
155 case 0x3e: Key
->ScanCode
= SCAN_F4
; break;
156 case 0x3f: Key
->ScanCode
= SCAN_F5
; break;
157 case 0x40: Key
->ScanCode
= SCAN_F6
; break;
158 case 0x41: Key
->ScanCode
= SCAN_F7
; break;
159 case 0x42: Key
->ScanCode
= SCAN_F8
; break;
160 case 0x43: Key
->ScanCode
= SCAN_F9
; break;
161 case 0x44: Key
->ScanCode
= SCAN_F10
; break;
162 case 0x01: Key
->ScanCode
= SCAN_ESC
; break;
166 // If there's a scan code pass it, and don't pass the char code
168 if (Key
->ScanCode
== 0) {
169 Key
->UnicodeChar
= InputRecord
->Event
.KeyEvent
.uChar
.UnicodeChar
;
170 if (Key
->UnicodeChar
== 0) {
171 return EFI_NOT_READY
;
181 WinNtSimpleTextInReadKeyStroke (
182 IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL
*This
,
183 OUT EFI_INPUT_KEY
*Key
189 TODO: Add function description
193 This - TODO: add argument description
194 Key - TODO: add argument description
198 EFI_DEVICE_ERROR - TODO: Add description for return value
199 EFI_NOT_READY - TODO: Add description for return value
204 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
205 INPUT_RECORD InputRecord
;
208 Private
= WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This
);
210 Status
= WinNtSimpleTextInCheckKey (Private
);
211 if (EFI_ERROR (Status
)) {
217 if (!Private
->WinNtThunk
->ReadConsoleInput (Private
->NtInHandle
, &InputRecord
, 1, &NtEventCount
)) {
218 return EFI_DEVICE_ERROR
;
221 if (NtEventCount
== 0) {
222 return EFI_NOT_READY
;
226 // Convert the Input Record to an EFI Keystroke.
228 Status
= WinNtConvertInputRecordToEfiKey (&InputRecord
, Key
);
229 } while (EFI_ERROR (Status
));
237 WinNtSimpleTextInWaitForKey (
245 TODO: Add function description
249 Event - TODO: add argument description
250 Context - TODO: add argument description
254 TODO: add return values
258 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
261 Private
= (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*) Context
;
262 Status
= WinNtSimpleTextInCheckKey (Private
);
263 if (!EFI_ERROR (Status
)) {
264 gBS
->SignalEvent (Event
);
270 WinNtSimpleTextInCheckKey (
271 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
277 TODO: Add function description
281 Private - TODO: add argument description
285 TODO: add return values
289 INPUT_RECORD
*InputRecord
;
291 DWORD ActualNtEventCount
;
299 Private
->WinNtThunk
->GetNumberOfConsoleInputEvents (Private
->NtInHandle
, &NtEventCount
);
300 if (NtEventCount
== 0) {
301 Status
= EFI_NOT_READY
;
305 InputRecord
= AllocatePool (sizeof (INPUT_RECORD
) * NtEventCount
);
306 if (InputRecord
== NULL
) {
307 Status
= EFI_NOT_READY
;
311 Success
= (BOOLEAN
) Private
->WinNtThunk
->PeekConsoleInput (
318 Status
= EFI_NOT_READY
;
322 Status
= EFI_NOT_READY
;
323 for (Index
= 0; Index
< (UINTN
) ActualNtEventCount
; Index
++) {
325 // Convert the Input Record to an EFI Keystroke.
327 Status
= WinNtConvertInputRecordToEfiKey (&InputRecord
[Index
], &Key
);
328 if (!EFI_ERROR (Status
)) {
329 Status
= EFI_SUCCESS
;
335 if (InputRecord
!= NULL
) {
336 FreePool (InputRecord
);
343 WinNtSimpleTextInAttachToWindow (
344 IN WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
350 TODO: Add function description
354 Private - TODO: add argument description
358 TODO: add return values
364 Private
->NtInHandle
= Private
->WinNtThunk
->GetStdHandle (STD_INPUT_HANDLE
);
366 Private
->SimpleTextIn
.Reset
= WinNtSimpleTextInReset
;
367 Private
->SimpleTextIn
.ReadKeyStroke
= WinNtSimpleTextInReadKeyStroke
;
369 Status
= gBS
->CreateEvent (
372 WinNtSimpleTextInWaitForKey
,
374 &Private
->SimpleTextIn
.WaitForKey
376 ASSERT_EFI_ERROR (Status
);