Set a max length to playdate.keyboard

So I'm creating an arcade-y High Score screen where the user can enter their initials. This is what it looks like so far:


Currently if the 3rd character matches the 4th character I'm calling keyboard.hide(), otherwise i'm manually truncating the text.

I thought it would be awesome if there was a way to set a maxLength that once reached the "ok" button would automatically be highlighted. So a subsequent "a" press would confirm & hide the keyboard, or a "b" button would move the highlight back to either the last used character or the one that was just removed (in case it was removed in error).

If the maxLength isn't possible then perhaps a method to set the highlight to any key including "ok".

A couple of use cases:

  • The player doesn't care so they just mash the "a" button to enter AAA. On the fourth press it would auto confirm and hide the keyboard.
  • Or in my case I'm currently pre-filling the last used initials in the keyboard using and the player would just need to press "a" button to confirm instead moving to the right and the confirming, or have the chance to change in case they handed it to someone else.

I'm currently getting by using a combination of other methods. But figured I'd put in a request for a nice-to-have. Since currently I'll need to put a prompt on the screen to "teach" the player. But the highlighting of "ok" might be more obvious.



Keyboard is a lua script in CoreLibs, that you can copy to your project and modify like I did, then import your local copy.


Awesome! I didn't even think to try this, thank you!