T-vK / ESP32-BLE-Keyboard

Bluetooth LE Keyboard library for the ESP32 (Arduino IDE compatible)
2.28k stars 379 forks source link

russian symbols #234

Open kraa965 opened 1 year ago

kraa965 commented 1 year ago

hi, tell me, is it possible to implement the output of Russian characters and, if possible, explain how this can be done?

alexz006 commented 1 year ago

ESP sends a "physical" key press, just like on a regular keyboard. Therefore, to input Russian characters (or any other language), you need to send a key combination to switch the keyboard layout.

kraa965 commented 1 year ago

This is how Russian characters are printed if you change the language image But if you write the code in this way, then everything is output correctly image image but there is a task so that the user can use both languages, so that it is possible to implement this without switching languages?

alexz006 commented 1 year ago

You cannot write Russian text using blekeyboard.println(). As an alternative, translate Cyrillic characters into Latin characters, as on a keyboard, and then perform blekeyboard.println(). Something like this:

void Keyboard_println(String text) {
  delay(200);
  String latinText = "";
  for (int i = 0; i < text.length(); i++) {
    char cyrillicChar = text.charAt(i);
    char latinChar;

    switch (cyrillicChar) {
      case 'а':
        latinChar = 'f';
        break;
      case 'б':
        latinChar = ',';
        break;
      // add the rest of the symbols and their correspondences here
      default:
        // If the symbol is not found, leave it unchanged.
        latinChar = cyrillicChar;
        break;
    }

    latinText += latinChar;
  }

  blekeyboard.println(latinText);
}
kraa965 commented 1 year ago

You cannot write Russian text using blekeyboard.println(). As an alternative, translate Cyrillic characters into Latin characters, as on a keyboard, and then perform blekeyboard.println(). Something like this:

void Keyboard_println(String text) {
  delay(200);
  String latinText = "";
  for (int i = 0; i < text.length(); i++) {
    char cyrillicChar = text.charAt(i);
    char latinChar;

    switch (cyrillicChar) {
      case 'а':
        latinChar = 'f';
        break;
      case 'б':
        latinChar = ',';
        break;
      // add the rest of the symbols and their correspondences here
      default:
        // If the symbol is not found, leave it unchanged.
        latinChar = cyrillicChar;
        break;
    }

    latinText += latinChar;
  }

  blekeyboard.println(latinText);
}

thank you, and if the text is passed not as a String, but as a char *text? and this code does not work image