🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Tab5 USBHIDKeyboard

    General
    1
    1
    8
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      jalmalogni
      last edited by

      I am attempting to use Tab5 to send keyboard events through a usb connection. I am able to use similar code to send keystrokes when using a Cardputer. I took the touch button example and added keyboard print(string) and write(keycode) to the button event. I also tried adding a delay after calling keyboard.begin()

      Using the same cable connection, the Cardputer successfully sends keyboard events to the computer, but the computer does not seem to receive any events from the Tab5.

      Is any way I can try to debug this?

      #include <M5Unified.h>
      #include <M5GFX.h>
      
      #include "USB.h"
      #include "USBHIDKeyboard.h"
      
      m5::touch_detail_t touchDetail;
      static int32_t w;
      static int32_t h;
      
      LGFX_Button button;
      
      USBHIDKeyboard Keyboard;
      
      void setup() {
        M5.begin();
      
        w = M5.Lcd.width();
        h = M5.Lcd.height();
        
        M5.Lcd.fillScreen(WHITE);
        M5.Display.setRotation(0);
        M5.Display.setTextDatum(top_center);
        M5.Display.drawString("Button Released", w / 2, 0, &fonts::FreeMonoBold24pt7b);
      
        button.initButton(&M5.Lcd, w / 2, h / 2, 200, 200, TFT_BLUE, TFT_YELLOW, TFT_BLACK, "BTN", 4, 4);
        button.drawButton();
      
      
        Keyboard.begin();
        USB.begin();
        delay(4000);
      
        M5.Display.drawString("usb done", w / 2, 100, &fonts::FreeMonoBold24pt7b);
        
      }
      
      
      
      void loop() {
        M5.update();
        touchDetail = M5.Touch.getDetail();
      
        if (touchDetail.isPressed()) {
          if(button.contains(touchDetail.x, touchDetail.y)){
              M5.Display.drawString("Button  Pressed", w / 2, 0, &fonts::FreeMonoBold24pt7b);
              Keyboard.print("hello");
              Keyboard.write(KEY_RETURN);
              delay(2000);
          }
        }
        else {
          M5.Display.drawString("Button Released", w / 2, 0, &fonts::FreeMonoBold24pt7b);
        }
      } 
      
      
      1 Reply Last reply Reply Quote 0
      • First post
        Last post