keyboard emulation for tablets and smartphones

Hi all,

I am working on emulating a keyboard with Arduino Leonardo.

I use the KeyboardAzertyFr library (based on Keyboard library).

It is working perfectly on computers (windows 7 and 10), on Galaxy Tab A (Android 7) but it not working properly on Samsung A3 (Android 7), Galaxy Tab Active (Android 5.1.1).

Sometimes (most of the time) only the first character of the string is printed.
If I loop on my buffer characters it is the same, only the first or some characters are printed.

I though it could be due to the keyboard setup but they are the same.
The OS can be the same also but it is working on Galaxy Tab A and not on Samsung A3.
I thought also it could be the power of the tablet which is too low so I added an external power with the power jack, but I still got the problem.

Did you face this problem ? Do you know how to solve it ?

Many thanks !

Post a link to the used library and post your complete code!

I guess that the smaller devices aren't able to detect more than one key pressed but that's only a wild guess.

Hi,
The library is this one : KeyboardAzertyFr - Arduino Libraries
But I tested with the Keyboard library and I have the same issue.

The code is here :

#include <HID.h>
#include <KeyboardAzertyFr.h>

boolean etatBouton;
int pinBouton;

void setup()
{
    pinBouton=9;                                     
    pinMode(pinBouton,INPUT); 
    KeyboardAzertyFr.begin();
}


void loop()
{
  etatBouton=digitalRead(pinBouton);
  
  if(etatBouton==HIGH)                                   
 { 
   KeyboardAzertyFr.print("hello world");
   KeyboardAzertyFr.write(KEY_RETURN);
   delay(1000);
  } 
     
}

This prints sometimes "hello world", sometimes "h".

Thanks

I would try editing KeyboardAzertyFr.cpp's print() write() function to add a delay between the press() and release() calls. You might need to add #include <Arduino.h> to get the delay() function. The current code sends all the keystrokes super quickly and that might be the cause of the problem.

I haven't tried Keyboard on my tablet yet, but I have not had good results getting the Mouse library working reliably on my tablet, despite having a lot of experience using it successfully on my computer. I somewhat blame it on my cheapo, low performance tablet.

Perhaps the keys are typing too fast? Try putting a short delay between the key-down and the key-up.

size_t KeyboardAzertyFr_::write(uint8_t c)
{
	uint8_t p = press(c);  // Keydown
        delay(100);      // Slow down to below ten keys a second.
	release(c);            // Keyup
	return p;              // just return the result of press() since release() almost always returns 1
}

If that works, try reducing the delay to see how fast you can go and still get reliable results.

It's working, thank you !
I started with a 100ms delay and I'll try to go down.

Thanks again for your help.