First commit

This commit is contained in:
wcjbr
2026-08-15 19:11:54 +08:00
commit 5f51a52ca6
18 changed files with 982 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
add_executable(keyinput main.cpp)
target_link_libraries(keyinput PRIVATE ConsoleLib)
+63
View File
@@ -0,0 +1,63 @@
#include <ConsoleLib.h>
using namespace ConsoleLib;
signed main() {
initConsole();
clearConsole();
printToConsole("ConsoleLib key input example\r\n");
printToConsole("Press arrow keys, Home/End, F1-F4, or any printable key.\r\n");
printToConsole("Press q or ESC to quit.\r\n");
while (true) {
// getConsoleKeyInput() 返回按键表并清空本次记录。
auto& keys = getConsoleKeyInput();
if (keys[KEY_UP]) {
printToConsole("UP\r\n");
}
if (keys[KEY_DOWN]) {
printToConsole("DOWN\r\n");
}
if (keys[KEY_LEFT]) {
printToConsole("LEFT\r\n");
}
if (keys[KEY_RIGHT]) {
printToConsole("RIGHT\r\n");
}
if (keys[KEY_HOME]) {
printToConsole("HOME\r\n");
}
if (keys[KEY_END]) {
printToConsole("END\r\n");
}
if (keys[KEY_F1]) {
printToConsole("F1\r\n");
}
if (keys[KEY_F2]) {
printToConsole("F2\r\n");
}
if (keys[KEY_F3]) {
printToConsole("F3\r\n");
}
if (keys[KEY_F4]) {
printToConsole("F4\r\n");
}
for (int c = 32; c < static_cast<int>(ASCII_TABLE_SIZE); ++c) {
if (keys[static_cast<Keycode>(c)]) {
char text[2] = {static_cast<char>(c), '\0'};
printToConsole(text);
}
}
if (keys[KEY_q] || keys[KEY_ESCAPE]) {
break;
}
sleep_ms(16);
}
quit(0);
}