virtual keyboard sample code
Monkey Forums/Monkey Programming/virtual keyboard sample code
| ||
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 |
| ||
Take a look at the AngelFont example in bananas/beaker. It has a simple input function that does exactly what you want. |
| ||
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. |
| ||
Works fine here. What's your OS and browser? |
| ||
Windows 7 64bit, Chrome |
| ||
Do you have any joy with bananas/mak/keyboardtest? If not you might want to file a bug report. |
| ||
bananas/mak/keyboardtest works well. It's the angelfont simpleinput that doesn't. |
| ||
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. |
| ||
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. |
| ||
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). |
| ||
Glad it works now. I suggest switching to a better browser. :) |
| ||
"I suggest switching to a better browser" hmmm. Let's hope that was a joke. |
| ||
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). |