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
32 // Private worker functions
36 WinNtSimpleTextInCheckKey (
37 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
42 WinNtSimpleTextInReset (
43 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
44 IN BOOLEAN ExtendedVerification
50 TODO: Add function description
54 This - TODO: add argument description
55 ExtendedVerification - TODO: add argument description
59 EFI_SUCCESS - TODO: Add description for return value
63 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
65 Private
= WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This
);
71 WinNtConvertInputRecordToEfiKey (
72 IN INPUT_RECORD
*InputRecord
,
73 OUT EFI_INPUT_KEY
*Key
79 TODO: Add function description
83 InputRecord - TODO: add argument description
84 Key - TODO: add argument description
88 EFI_NOT_READY - TODO: Add description for return value
89 EFI_NOT_READY - TODO: Add description for return value
90 EFI_NOT_READY - TODO: Add description for return value
91 EFI_SUCCESS - TODO: Add description for return value
96 // Make sure InputRecord is an event that represents a keypress
98 if (InputRecord
->EventType
== KEY_EVENT
) {
99 if (!InputRecord
->Event
.KeyEvent
.bKeyDown
) {
100 return EFI_NOT_READY
;
103 return EFI_NOT_READY
;
107 // Check to see if we should return a scan code in place of Unicode character.
110 Key
->UnicodeChar
= 0;
111 if ((InputRecord
->Event
.KeyEvent
.dwControlKeyState
& (NUMLOCK_ON
| ENHANCED_KEY
)) != NUMLOCK_ON
) {
113 // Only check these scan codes if num lock is off.
115 switch (InputRecord
->Event
.KeyEvent
.wVirtualScanCode
) {
116 case 0x48: Key
->ScanCode
= SCAN_UP
; break;
117 case 0x50: Key
->ScanCode
= SCAN_DOWN
; break;
118 case 0x4d: Key
->ScanCode
= SCAN_RIGHT
; break;
119 case 0x4b: Key
->ScanCode
= SCAN_LEFT
; break;
120 case 0x47: Key
->ScanCode
= SCAN_HOME
; break;
121 case 0x4F: Key
->ScanCode
= SCAN_END
; break;
122 case 0x52: Key
->ScanCode
= SCAN_INSERT
; break;
123 case 0x53: Key
->ScanCode
= SCAN_DELETE
; break;
124 case 0x49: Key
->ScanCode
= SCAN_PAGE_UP
; break;
125 case 0x51: Key
->ScanCode
= SCAN_PAGE_DOWN
; break;
129 switch (InputRecord
->Event
.KeyEvent
.wVirtualScanCode
) {
130 case 0x3b: Key
->ScanCode
= SCAN_F1
; break;
131 case 0x3c: Key
->ScanCode
= SCAN_F2
; break;
132 case 0x3d: Key
->ScanCode
= SCAN_F3
; break;
133 case 0x3e: Key
->ScanCode
= SCAN_F4
; break;
134 case 0x3f: Key
->ScanCode
= SCAN_F5
; break;
135 case 0x40: Key
->ScanCode
= SCAN_F6
; break;
136 case 0x41: Key
->ScanCode
= SCAN_F7
; break;
137 case 0x42: Key
->ScanCode
= SCAN_F8
; break;
138 case 0x43: Key
->ScanCode
= SCAN_F9
; break;
139 case 0x44: Key
->ScanCode
= SCAN_F10
; break;
140 case 0x01: Key
->ScanCode
= SCAN_ESC
; break;
144 // If there's a scan code pass it, and don't pass the char code
146 if (Key
->ScanCode
== 0) {
147 Key
->UnicodeChar
= InputRecord
->Event
.KeyEvent
.uChar
.UnicodeChar
;
148 if (Key
->UnicodeChar
== 0) {
149 return EFI_NOT_READY
;
159 WinNtSimpleTextInReadKeyStroke (
160 IN EFI_SIMPLE_TEXT_IN_PROTOCOL
*This
,
161 OUT EFI_INPUT_KEY
*Key
167 TODO: Add function description
171 This - TODO: add argument description
172 Key - TODO: add argument description
176 EFI_DEVICE_ERROR - TODO: Add description for return value
177 EFI_NOT_READY - TODO: Add description for return value
182 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
183 INPUT_RECORD InputRecord
;
186 Private
= WIN_NT_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This
);
188 Status
= WinNtSimpleTextInCheckKey (Private
);
189 if (EFI_ERROR (Status
)) {
195 if (!Private
->WinNtThunk
->ReadConsoleInput (Private
->NtInHandle
, &InputRecord
, 1, &NtEventCount
)) {
196 return EFI_DEVICE_ERROR
;
199 if (NtEventCount
== 0) {
200 return EFI_NOT_READY
;
204 // Convert the Input Record to an EFI Keystroke.
206 Status
= WinNtConvertInputRecordToEfiKey (&InputRecord
, Key
);
207 } while (EFI_ERROR (Status
));
215 WinNtSimpleTextInWaitForKey (
223 TODO: Add function description
227 Event - TODO: add argument description
228 Context - TODO: add argument description
232 TODO: add return values
236 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
;
239 Private
= (WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*) Context
;
240 Status
= WinNtSimpleTextInCheckKey (Private
);
241 if (!EFI_ERROR (Status
)) {
242 gBS
->SignalEvent (Event
);
248 WinNtSimpleTextInCheckKey (
249 WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
255 TODO: Add function description
259 Private - TODO: add argument description
263 TODO: add return values
267 INPUT_RECORD
*InputRecord
;
269 DWORD ActualNtEventCount
;
277 Private
->WinNtThunk
->GetNumberOfConsoleInputEvents (Private
->NtInHandle
, &NtEventCount
);
278 if (NtEventCount
== 0) {
279 Status
= EFI_NOT_READY
;
283 InputRecord
= AllocatePool (sizeof (INPUT_RECORD
) * NtEventCount
);
284 if (InputRecord
== NULL
) {
285 Status
= EFI_NOT_READY
;
289 Success
= (BOOLEAN
) Private
->WinNtThunk
->PeekConsoleInput (
296 Status
= EFI_NOT_READY
;
300 Status
= EFI_NOT_READY
;
301 for (Index
= 0; Index
< (UINTN
) ActualNtEventCount
; Index
++) {
303 // Convert the Input Record to an EFI Keystroke.
305 Status
= WinNtConvertInputRecordToEfiKey (&InputRecord
[Index
], &Key
);
306 if (!EFI_ERROR (Status
)) {
307 Status
= EFI_SUCCESS
;
313 if (InputRecord
!= NULL
) {
314 FreePool (InputRecord
);
321 WinNtSimpleTextInAttachToWindow (
322 IN WIN_NT_SIMPLE_TEXT_PRIVATE_DATA
*Private
328 TODO: Add function description
332 Private - TODO: add argument description
336 TODO: add return values
342 Private
->NtInHandle
= Private
->WinNtThunk
->GetStdHandle (STD_INPUT_HANDLE
);
344 Private
->SimpleTextIn
.Reset
= WinNtSimpleTextInReset
;
345 Private
->SimpleTextIn
.ReadKeyStroke
= WinNtSimpleTextInReadKeyStroke
;
347 Status
= gBS
->CreateEvent (
348 EFI_EVENT_NOTIFY_WAIT
,
350 WinNtSimpleTextInWaitForKey
,
352 &Private
->SimpleTextIn
.WaitForKey
354 ASSERT_EFI_ERROR (Status
);