我们知道,可以使用 ConOut 下面的 SetCursorPosition 来设置光标输出的位置【参考1】。
但是,找了一圈也没有找到 GetCursorPosition ,我怎么知道当前光标在哪呢?查查C手册,通常使用conio.h 中的 wherex,wherey 来完成这个功能。问题是, clib 连这个头文件都没有……..
经过一番查找,在【参考2】中有人提到可以使用 Mode 中的 CursorColumn 和 CursorRow 来完成这个功能。于是,编写简单的程序验证一下,程序非常简单,随机生成一个位置显示X,然后在它后面输出当前这个X的位置:
#include <Uefi.h> #include <Library/UefiLib.h> #include <Library/ShellCEntryLib.h> #include <stdio.h> #include <stdlib.h> #include <wchar.h> #include <Protocol/EfiShell.h> #include <Library/ShellLib.h> #include <Protocol/SimpleFileSystem.h> #include <Protocol/BlockIo.h> #include <Library/DevicePathLib.h> #include <Library/HandleParsingLib.h> #include <Library/SortLib.h> #include <Library/MemoryAllocationLib.h> #include <Library/BaseMemoryLib.h> extern EFI_SYSTEM_TABLE *gST; /** Get the position of cursor **/ VOID GetCursorPosition( IN UINTN *x, IN UINTN *y ) { *x = gST->ConOut->Mode->CursorColumn; *y = gST->ConOut->Mode->CursorRow; return; } int EFIAPI main ( IN int Argc, IN char **Argv ) { UINTN wherex; UINTN wherey; UINTN i; for (i=0; i<5; i++) { gST -> ConOut -> SetCursorPosition(gST -> ConOut,rand()%70,rand() % 20); GetCursorPosition(&wherex,&wherey); Print(L"x[%02d]:[%02d] ",wherex, wherey); } return EFI_SUCCESS; }
运行结果:
完整代码下载:
参考:
1.UEFI Spec 2.4 P460
2.http://biosren.com/viewthread.php?tid=4164&highlight=%B9%E2%B1%EA EFI下对应wherex()作用的FUN是哪个?该怎么用?
请问一下我使用你的程序在EDK2下面可以编译过去。可以在本地执行,但是为什么不能在实体机器下面运行呢?谢谢
你是在EDK2中编译然后放在实体机器上运行的么?
大大,你知道如何得到Cursor位置的值嗎? 可能是個 字元 或 數字
我目前想的方法是把資料dump進.txt檔,再從.txt把值讀出來= =
你的目标就是读取指定位置处的ascii吧?
这个问题我考察过,uefi 没有函数能够直接完成这个功能。
不过我觉得可以通过抓图然后特征识别的方式来实现这个功能,
猜测而已没有实验过。
順便想問一下,1.如何把螢幕上的資訊匯入到資料夾?
2.從資料夾比對我所需要的字串?
哈哈 問題有點多
暂时能做的是截图,还没有办法取得字符本身
http://www.lab-z.com/scrcap/