virtual keyboard sample code

Monkey Forums/Monkey Programming/virtual keyboard sample code

C10B(Posted 2013) [#1]
Hi, I want a simple entry field in my game where a user can enter their name. Is there any sample code I can, ahem, borrow? to help me start off on the right track? I'm aiming mainly as iOS and Android and it seems sensible to use the built in virtual keyboards.

Many thanks


Beaker(Posted 2013) [#2]
Take a look at the AngelFont example in bananas/beaker. It has a simple input function that does exactly what you want.


C10B(Posted 2013) [#3]
Thanks beaker. Should that simpleinput thing work in html5 too, ie with a real keyboard? I've run the sample but nothing seems to work as text input, I just see text rendered to the screen.


Beaker(Posted 2013) [#4]
Works fine here. What's your OS and browser?


C10B(Posted 2013) [#5]
Windows 7 64bit, Chrome


Beaker(Posted 2013) [#6]
Do you have any joy with bananas/mak/keyboardtest? If not you might want to file a bug report.


C10B(Posted 2013) [#7]
bananas/mak/keyboardtest works well. It's the angelfont simpleinput that doesn't.


Beaker(Posted 2013) [#8]
I think you probably don't have the latest version of AngelFont. Take a look here and try that version:
http://www.monkeycoder.co.nz/Community/posts.php?topic=141
.. let me know how you get on. Chrome seems quite a bit slower here than Firefox, which is probably partly to blame for your problem.

Weirdly I also noticed that the simpleinput cursor doesn't show up on Chrome on WinXP, but it seems fine in Firefox, are you getting that as well? That could be speed related as well.


Beaker(Posted 2013) [#9]
A fix for the cursor problem is to change the Draw:Void(x:Int,y:Int) function in simpleinput.monkey to:
	Method Draw:Void(x:Int,y:Int)
		font.DrawText(text,x,y)
		count = (count+1) Mod 3
		If count > 1 DrawRect x+font.TextWidth(text[..cursorPos]),y+heightOffset,cursorWidth,height
	End Method

And remove the line:
count = (count+1) Mod 7
..from the Update:String() function in simpleinput.monkey.

Hope this helps.


C10B(Posted 2013) [#10]
Thanks Beaker, that changes does allow me to type into the simpleinput in Chrome. It's a bit like typing through treacle though! Unusably sluggish, but fine for me testing my app (as I want to deliver to iOS, not HTML5 anyway).


Beaker(Posted 2013) [#11]
Glad it works now. I suggest switching to a better browser. :)


C10B(Posted 2013) [#12]
"I suggest switching to a better browser"
hmmm. Let's hope that was a joke.


c.k.(Posted 2013) [#13]
NEVERMIND THIS POST...


Interestingly, the simpleinput.monkey example just displays a white screen for me. (Oh, probably because it doesn't do anything... heh.)

The angelfont_example.monkey works fine (accepts input from keyboard).