aboutsummaryrefslogtreecommitdiffstats
path: root/Lessons/Lesson_39/UefiLessonsPkg
diff options
context:
space:
mode:
authorKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-14 12:54:56 +0300
committerKonstantin Aladyshev <aladyshev22@gmail.com>2021-07-14 12:54:56 +0300
commitfb03061a2a68dd70dda54ddcb74c8fe92d994c0a (patch)
tree119fa90684b74f0a4a21145281729fe130bd9f36 /Lessons/Lesson_39/UefiLessonsPkg
parent418cd8555d3a8963229ccb22ca85c2af4bfb13b2 (diff)
downloadUEFI-Lessons-fb03061a2a68dd70dda54ddcb74c8fe92d994c0a.tar.gz
UEFI-Lessons-fb03061a2a68dd70dda54ddcb74c8fe92d994c0a.tar.bz2
UEFI-Lessons-fb03061a2a68dd70dda54ddcb74c8fe92d994c0a.zip
Add lesson 39
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
Diffstat (limited to 'Lessons/Lesson_39/UefiLessonsPkg')
-rwxr-xr-xLessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.c107
-rwxr-xr-xLessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.inf22
2 files changed, 129 insertions, 0 deletions
diff --git a/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.c b/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.c
new file mode 100755
index 0000000..bb73c0c
--- /dev/null
+++ b/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.c
@@ -0,0 +1,107 @@
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiLib.h>
+
+#include <Protocol/SimpleTextInEx.h>
+
+
+EFI_HANDLE NotifyHandle;
+EFI_HANDLE NotifyHandle1;
+
+EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL* InputEx = NULL;
+
+EFI_STATUS EFIAPI MyKeyNotificationFunction(EFI_KEY_DATA* KeyData)
+{
+ Print(L"\nHot Key 1 is pressed");
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS EFIAPI MyKeyNotificationFunction1(EFI_KEY_DATA* KeyData)
+{
+ Print(L"\nHot Key 2 is pressed");
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+HotKeyDriverUnload(
+ IN EFI_HANDLE ImageHandle
+ )
+{
+ if (!InputEx)
+ return EFI_SUCCESS;
+
+ EFI_STATUS Status;
+
+ if (!NotifyHandle) {
+ Status = InputEx->UnregisterKeyNotify(InputEx,
+ (VOID*)NotifyHandle);
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't perform RegisterKeyNotify: %r", Status);
+ return Status;
+ }
+ }
+
+ if (!NotifyHandle1) {
+ Status = InputEx->UnregisterKeyNotify(InputEx,
+ (VOID*)NotifyHandle1);
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't perform RegisterKeyNotify: %r", Status);
+ return Status;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+HotKeyDriverEntryPoint(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status = gBS->LocateProtocol(
+ &gEfiSimpleTextInputExProtocolGuid,
+ NULL,
+ (VOID**)&InputEx
+ );
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't locate EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL: %r", Status);
+ return Status;
+ }
+
+ EFI_KEY_DATA HotKey;
+ HotKey.Key.ScanCode = 0;
+ HotKey.Key.UnicodeChar = L'z';
+ HotKey.KeyState.KeyShiftState = EFI_LEFT_CONTROL_PRESSED | EFI_LEFT_ALT_PRESSED | EFI_SHIFT_STATE_VALID;
+ HotKey.KeyState.KeyToggleState = 0;
+
+ Status = InputEx->RegisterKeyNotify(InputEx,
+ &HotKey,
+ MyKeyNotificationFunction,
+ (VOID**)&NotifyHandle);
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't perform RegisterKeyNotify: %r", Status);
+ return Status;
+ }
+
+ HotKey.KeyState.KeyShiftState = 0;
+ HotKey.KeyState.KeyToggleState = EFI_TOGGLE_STATE_VALID | EFI_NUM_LOCK_ACTIVE | EFI_KEY_STATE_EXPOSED;
+
+ Status = InputEx->RegisterKeyNotify(InputEx,
+ &HotKey,
+ MyKeyNotificationFunction1,
+ (VOID**)&NotifyHandle1);
+
+ if (EFI_ERROR(Status)) {
+ Print(L"Error! Can't perform RegisterKeyNotify: %r", Status);
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.inf b/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.inf
new file mode 100755
index 0000000..fa04f32
--- /dev/null
+++ b/Lessons/Lesson_39/UefiLessonsPkg/HotKeyDriver/HotKeyDriver.inf
@@ -0,0 +1,22 @@
+[Defines]
+ INF_VERSION = 1.25
+ BASE_NAME = HotKeyDriver
+ FILE_GUID = da316635-c66f-477e-9df6-880d2d729f1b
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ ENTRY_POINT = HotKeyDriverEntryPoint
+ UNLOAD_IMAGE = HotKeyDriverUnload
+
+[Sources]
+ HotKeyDriver.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[Protocols]
+ gEfiSimpleTextInputExProtocolGuid
+
+[LibraryClasses]
+ UefiDriverEntryPoint
+ UefiLib
+