Keyboard input to text element

Hi y’al hope you all are doing well, so I am a little bit stuck on keyboard input. I want to take the input value of keyboard (numbers…) and assign them to text element. Like this video

this is done in unity I want the same behavior in Playcanvas also with the virtual keyboard which are button element in the video. Can anyone help me with this it would be a huge help. Thanks

Hi there!

If you are looking fot only numbers and don’t need support for special characters this should be quite simple I think.
Maybe something like this could do it?

//array to populate with numbers
let charArray = [];

// listen to keypresses"keydown", onKeyDown, this);

// handle keyboard events
var onKeyDown = function (e) {
    if (e.key === pc.KEY_1) {
    if (e.key === pc.KEY_2) {
    this.inputEntity.element.text = charArray.join();

For virtual keyboard you can detect mouse events (e.g. clicking buttons) and push characters into the same array


1 Like

This works great thanks alot.

1 Like