Disable keyboard input

Hello

I have simple application that allows keyboard input and blinking cursor. How to disable keyboard input and remove cursor?

#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include "lv_drivers/indev/mouse.h"
#include <stdio.h>
#include <unistd.h>
#include "lv_examples/lv_examples.h"
#include <time.h>
#include <sys/time.h>

#define DISP_BUF_SIZE 800 * 600 * 4UL // If smaller than screen memory, draw will occur in chunks


static void event_handler(lv_obj_t * obj, lv_event_t event)
{
    if(event == LV_EVENT_CLICKED) {
        printf("Clicked\n");
    } else if(event == LV_EVENT_VALUE_CHANGED) {
        printf("Toggled\n");
    }
}

void lv_ex_btn_1(void)
{
    lv_obj_t * label;

    lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL);
    lv_obj_set_event_cb(btn1, event_handler);
    lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -100);
    lv_obj_set_size(btn1, 300, 200);

    label = lv_label_create(btn1, NULL);
    lv_label_set_text(label, "Button");

    lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);

    lv_obj_set_event_cb(btn2, event_handler);
    lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 100);

    lv_btn_set_checkable(btn2, true);
    lv_btn_toggle(btn2);
    lv_btn_set_fit2(btn2, LV_FIT_NONE, LV_FIT_TIGHT);
    lv_obj_set_size(btn2, 300, 200);
    label = lv_label_create(btn2, NULL);
    lv_label_set_text(label, "Toggled");
}


int main(void)
{
    
    lv_init();
    
    fbdev_init();
    /*Small buffers for LittlevGL to draw the screen's content with double-buffering*/
    static lv_color_t buf1[DISP_BUF_SIZE];
    static lv_color_t buf2[DISP_BUF_SIZE];

    /*Initialize a descriptor for the buffer, with double buffering*/
    static lv_disp_buf_t disp_buf;
    lv_disp_buf_init(&disp_buf, buf1, buf2, DISP_BUF_SIZE);
    /*Initialize and register a display driver*/
    // Here we use the special callback function specific for the Linux Framebuffer Driver
    lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&disp_drv);
    disp_drv.buffer   = &disp_buf;
    disp_drv.flush_cb = fbdev_flush;
    lv_disp_drv_register(&disp_drv);

    // Initialize EVDEV input for the 52pi touchscreen,
    // which luckily is supported as an "event input device" by the kernel
    evdev_init();
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&indev_drv);
    indev_drv.type    = LV_INDEV_TYPE_POINTER;
    indev_drv.read_cb = evdev_read;
    lv_indev_t *  mouse_indev = lv_indev_drv_register(&indev_drv);

    LV_IMG_DECLARE(mouse_cursor_icon);                         /*Declare the image file.*/
    lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); /*Create an image object for the cursor */
    lv_img_set_src(cursor_obj, &mouse_cursor_icon);            /*Set the image source*/
    lv_indev_set_cursor(mouse_indev, cursor_obj);              /*Connect the image  object to the driver*/
    

    
    lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(label1, "Function 1");
    lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL);
    lv_label_set_text(label2, "Section A");

    // Alignment
    // NULL = align on parent (the screen)
    lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0);
    lv_obj_align(label2, NULL, LV_ALIGN_IN_TOP_MID, 0, 0);

    // Add a button
    lv_ex_btn_1();

    /*Handle LitlevGL tasks (tickless mode)*/
    // Mandatory, otherwise nothing will be displayed
    // It allows the callback functions to operate (for example to actually transfer bytes to screen framebuffer)
    while(1) {
        lv_tick_inc(5);
        lv_task_handler();
        usleep(5000);
    }

    return 0;
}



uint32_t custom_tick_get(void)
{
    static uint64_t start_ms = 0;
    if(start_ms == 0) {
        struct timeval tv_start;
        gettimeofday(&tv_start, NULL);
        start_ms = (tv_start.tv_sec * 1000000 + tv_start.tv_usec) / 1000;
    }

    struct timeval tv_now;
    gettimeofday(&tv_now, NULL);
    uint64_t now_ms;
    now_ms = (tv_now.tv_sec * 1000000 + tv_now.tv_usec) / 1000;

    uint32_t time_ms = now_ms - start_ms;
    return time_ms;
}

Looking at your code, there are two things to address:

1. Remove the Mouse Cursor

Your code creates a cursor image object and links it to the input device. The cursor object is clickable by default, which also blocks UI events. To remove it, simply don’t create the cursor object and don’t call lv_indev_set_cursor. Remove these lines:

LV_IMG_DECLARE(mouse_cursor_icon);
lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL);
lv_img_set_src(cursor_obj, &mouse_cursor_icon);
lv_indev_set_cursor(mouse_indev, cursor_obj);

If you ever do want to show a cursor object, make sure to disable its clickable flag to avoid blocking UI events

lv_obj_set_click(cursor_obj, false);

2. Disable Keyboard/Pointer Input

You can disable the registered input device using lv_indev_enable(), passing false to disable it:

lv_indev_enable(mouse_indev, false);

This will disable the evdev pointer input device you registered. Pass NULL instead of mouse_indev to disable all input devices at once.

3. Hide the Linux Framebuffer Terminal Cursor

You can hide the terminal blinking on the corner by doing this:

sudo /usr/bin/tput civis > /dev/tty1

Or, for a persistent solution across reboots, add vt.global_cursor_default=0 to your kernel command line (e.g., cmdline.txt or uEnv.txt depending on your board).