64 lines
1.5 KiB
C++
64 lines
1.5 KiB
C++
#include <ConsoleLib.hpp>
|
|
|
|
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);
|
|
}
|