Arduino Keyboard vs Real Keyboard on Android

Hi everyone! I have an Arduino Pro Micro that I was planning to use as a keyboard that automatically enters the passcode to an Android phone. I want to just plug the Arduino and not have to wake the phone first and swipe up to get to the on-screen keypad that appears to enter the passcode. So I tried it first with a real keyboard to see if there is a key that wakes the phone and opens the on-screen keypad, and, to my surprise, it doesn't matter which key I press they all do what I want if I press any key the phone wakes up, then if I press any other key the keypad appears.

Now the problem Is that the Arduino wakes the phone but is unable to get to the on-screen keypad, this is my code

#include "Keyboard.h"

void setup() {
    // put your setup code here, to run once:
    delay(10000);
    Keyboard.begin();
    Keyboard.println(0); //<------Works, wakes the phone
    delay(2000);
    Keyboard.println(0); //<------Doesn't work, doesn't open the keypad
    Keyboard.end();
}
void loop() {
   // put your main code here, to run repeatedly:
}

Maybe Im missing something, I tried all the functions Keyboard.print(), Keyboard.println(), Keyboard.write() and Keyboard.press(), Keyboard.release()

I hope someone knows why the Arduino is not able to open de keypad, I tried with all this and various numbers and letters.

Thanks in advance.

I don't understand how this compiles. Is this a typing mistake?

Sorry I misspelled, it’s fixed know.

Never mind, I see you claim to have tried the below, sry.

That sends more than one character.

Try instead both places

Serial.write(65);

sends just the letter A.

Or another character, like

Serial.write(‘x’);

using a character constant.

When you paste code, it should come from something that compiles… no typos please! Saves us time and throwing back red herrings.

a7

OK... How do you enter a passcode on a USB keyboard? Let's say your passcode is "1234". Do you type '1', '2', '3', '4', 'Enter'? You should be able to do the same with the Arduino with Keyboard.println("1234");

Sometimes games get upset at how quickly the Arduino sends a 'release' after sending a 'press'. Maybe the android passcode is similar. You can work around that by doing the two operations separately with a slight delay:

    Keyboard.press('1');
    delay(10);
    Keyboard.release('1');

    Keyboard.press('2');
    delay(10);
    Keyboard.release('2');

    Keyboard.press('3');
    delay(10);
    Keyboard.release('3');

    Keyboard.press('4');
    delay(10);
    Keyboard.release('4');

    Keyboard.press('\n'); // Enter
    delay(10);
    Keyboard.release('\n');  // Enter

In that case, should there not be a delay between the "release" and the following "press"?

The OP is not trying to auto-enter or remote enter a passcode yet.

Any two "real" characters

first - wakes it up
second - brings up a keypad entry screen

and that doesn't obtain if the two characters are sent from the Arduino
first - wakes it up
second - does NOT bring up a keypad entry screen

There's a healthy human like delay between the two in the code…

So until that mystery is hurdled, s/he is stuck at, as I understand it.

@xebcam are you sure you did what you said?

I can't see why Serial.write wouldn't be sending along the characters, nor why the device would get the first such character and react properly but ignore, or react differently, to receiving the second.

a7

I have not seen anyone report problems with Keyboard not working because the time between .release() and subsequent .press() was too short. Have you?

I did exactly what I described, I'm also perplexed. I guess It has to be something to do with what is being sent by the Arduino and what a real keyboard sends.

Didn't worked, I used this code

#include "Keyboard.h"

void setup() {
    // put your setup code here, to run once:
    delay(10000);
    Keyboard.begin();
    Keyboard.press('1'); //<--- Works wakes the phone
    delay(500);
    Keyboard.release('1');
    delay(1500);
    Keyboard.press('2');
    delay(500);
    Keyboard.release('2');//<---Doesn't work, doesn't show keypad
    Keyboard.end();
}

void loop() {
    // put your main code here, to run repeatedly:

}

I haven't found or seen a case where the USB HID keyboard mechanism doesn't do the 'xact same thing as a "real" keyboards. Kinda the point.

I don't like to guess! There is an answer.

a7

I really hope so, also you said

Serial.write()

should work but I think what you meant was

Keyboard.write()

right?

Yes, thanks. Time for bed. :wink:

a7

Ok so I tried it with a Chinese Tablet on Android 5.0 and wake up works and the keypad works sending the SPACE key with

Keyboard.press(' ');

I also tried it with a Samsung Galaxy A10s on Android 10 and it Works with all the keys

My problem still remains with the Samsung Galaxy Note 9 on Android 9

Seems odd but I don't argue with success!

Good detective work, nice to have a few devices around to experiment with.

Now

Did you need to do the Keyboard.release()? Did you use, oh never mind, just…

Please post the entire sketch that works on two devices and fails on a third!

a7