Download

Making a VR keyboard ?

Hey everyone !

With VR in mind, i managed to get my (very complex) UI working on a UWidgetComponent and i’m very happy with it (fantastic work from epic dev team as always, thanks a lot !!).

Now there’s still one thing i need for it to be fully working with a DK2 on my head, and that’s the keyboard.
I need it to write into some SEditableText, for instance for players to change their name.

So i’m considering the options/strategies i could adopt. So, let’s take the “A” key, i need a button that can send an A into an editable text.

The brute force strategy would be something along:
When the A button is pressed:

  • note which SEditableText has the focus (because the UMG keyboard will take it when pressed)
  • put its content in a string
  • add an A at the end of the string
  • put the string back in the SEditableText.
  • give the focus back to the SEditableText.

This should work but seems a bit over complicated.

A much more elegant way would be to have some function that would say to the button “when pressed, do not take the focus and send exactly the same message as if the A key of the real physical keyboard had been pressed”.
So when i would press the slate button, it would write an A naturally in the selected SEditableText.

Is there a way to do that ?

Or maybe there’s some simpler/better strategy that i did not think of ? Like using the android virtual keyboard in a desktop game ? (i am developping for windows by the way)
Or anything even simpler that will put me to shame for posting this tread ??

Anyone with experience in this area before i try to reinvent the wheel ?

Cheers

Cedric

Don’t actually use a textbox. Just determine what key the user pressed and edit the text in a label, console style. Even have a key for backspace on the keyboard.

Hey Nick,

Thanks a lot for the fast answer but reading it i understand my question wasn’t clear, sorry about that.

My question was confusing because i used the word “making” incorrectly.

I know how to make (visually) a slate/umg keyboard. My question was rather “how do i make this keyboard-looking-UI behave like a virtual keyboard ?”

Let’s say my game was a social network, then i’m gonna ask the players to fill a registration form, with their name, email and whatnot.

Every field, let’s say the name, would be a SEditableText, and what i want is that when this field is clicked, a virtual keyboard pops up in game so people can fill the field without having to take their VR headset off and without even touching the real keyboard.

So when i mouse-click the A on the virtual slate-keyboard, is there an elegant way to tell it to behave exactly like the pressed-A of the real physical keyboard so that the game wouldn’t see the difference ?

I hope i made things a bit clearer, sorry again about my misuse of “make” :slight_smile:

Cedric

Hi there!

You can actually use WINAPI function SendInput to simulate any mouse or keyboard input. It’s not hard to understand or implement and this is how you do it:


// Begin native stuff
#include "AllowWindowsPlatformTypes.h"

        void SendKeyInputFromChar(char inChar)
	{
		INPUT i;
		i.type = INPUT_KEYBOARD;

		i.ki.wScan = inChar;
		i.ki.time = 0;
		i.ki.dwExtraInfo = 0;

		i.ki.wVk = 0;
		i.ki.dwFlags = KEYEVENTF_UNICODE;
		SendInput(1, &i, sizeof(INPUT));
	}

#include "HideWindowsPlatformTypes.h"
// End native stuff

Then, if you use SendKeyInputFromChar(‘A’) you will simulate ‘A’ key press.

Keep in mind that this is 100% native thing and might not work on different platforms. Maybe there is easier way to simulate input directly to UE.

I’m using this method for my pet project to create “hover-only” keyboard so user doesnt have to actually click buttons on keyboard to type ; )

That’s perfect, thanks a lot Szyszek, for the info and the idea !
:slight_smile:

Actually, this has been an outstanding issue for me for sometime now. I do have a virtual keyboard, complete with the keys, and edit control. But I was trying to find an elegant way to interface with the EditableTextBox. Unfortunately it’s not a control that accommodates this type of behavior.

And of course I first thought about stuffing the keyboard. But I suspect that’s probably Windows specific. Btw, given that you’re dealing with a VR device that may not work.

I see a few things now, looking this over again, and will give it a try and report back if I find something universal (if at all possible).

All right, thanks Jerry.

Yeah, given the huge explosion VR promises to be, i’m surprise how little this sort of question has been raised, probably because not so many of us have a vr headset right now.
Things are surely going to change with the arrival of htc vive and the consumer rift, can’t wait^^

It would be nice to have some nice native tools in ue4 lib to handle virtual input.
It will probably come in time, when the community has a better idea of how to handle VR input, which is still quite an uncharted territory.
The keyboard is certainly a central question.

I’m gonna try what i can and as always i will post any useful code i end up with.

Cheers
Cedric