What MCU/Processor/Board and compiler are you using?
lvgl simulator
What do you want to achieve?
Keyboard entry
What have you tried so far?
Code to reproduce
Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.
The code block(s) should be formatted like:
int main()
{
int ch;
while (1)
{
if (_kbhit())//If a key is pressed, the ﹐ kbhit() function returns true
{
ch = _getch(); //Use the function ﹐ getch() to get the key value pressed
std::cout << ch << std::endl;
if (ch == 27)
break;
}
Sleep(10); /*Just to let the system breath*/
}
}
system:windows 10 1909
compiler:msvc+clang
I just want to check the input of the keyboard and finish the interface switching. I read ‘lv_drives/keyboard.h’. But I didn’t understand it. I hope I can provide a demo.thank you.
int main(int argc, char **argv)
{
/*Initialize LittlevGL*/
lv_init();
/*Initialize the HAL (display, input devices, tick) for LittlevGL*/
hal_init();
//lv_group_t *g = lv_group_create();
/* Add your objects to the group */
lv_indev_drv_t real_kb_drv;
keyboard_init();
real_kb_drv.type = LV_INDEV_TYPE_KEYPAD;
real_kb_drv.read_cb = keyboard_read;
lv_indev_data_t kbDate;
while (1)
{
std::cout << " is pressed?" << keyboard_read(&real_kb_drv, &kbDate) << " ";
std::cout << "value: " << kbDate.key << std::endl;
Sleep(10); /*Just to let the system breath*/
}
is pressed?0 value: 51
is pressed?0 value: 51
is pressed?0 value: 51
is pressed?0 value: 52
is pressed?0 value: 52
is pressed?0 value: 52
This is valid. It just doesn’t check whether the keyboard is pressed or not.
But it’s not a big problem,It can also be realized with nowkeyval and lastkeyval variables
You shouldn’t call the keyboard_read function directly. It’s designed to be registered as a standard LittlevGL keypad driver, so that you can interact with it using standard keypad events or signals.
Tested by me _getch(); It is invalid.
Therefore, you must use the function in lv_driver ->keyboard.h-> bool keyboard_read(lv_indev_drv_t * indev_drv, lv_indev_data_t * data)to read the data.
I don’t know if it’s my msvc2019 + clang reason