GLBasic forum

Codesnippets => Code Snippets => Topic started by: ampos on 2011-Sep-19

Title: IMPUT$ (input$ in any device!)
Post by: ampos on 2011-Sep-19
This functions is the same as INPUT$ but it opens a virtual keyboard if target device has no keyboard.

Just call it as

Code: (glbasic) [Select]
t$=imput$(Text$,x,y)
Where "text" is a text :) to be displayed behind the input cursor.

At run, it asumes the device has keyboard and a "standard" input cursor is displayed. If the user touchs the screen, it now thinks you have no keyboard and a virtual keyboard is shown in screen. Now you can type using mouse/toouchscreen and keyboard.

It has been tested with Android (no keyboard) and Pre2 (keyboard) and it works great. Too lazy for iOS with/out bluetooth keyboard.

Due to my current development method, it has been created for a virtual screen enviroment.

You have to create a 1024x640 (16:10 aspect) screen 1 with sprite id "my_screen". This screen will be scaled and drawn to fit (with aspect ratio locked) the current screen (it has been tested on 480x320, 1024x768, 800x480 and looks great!).

The keyboard creates a virtual screen 2 with sprite id keyb_keyboard, but is not needed anything by the user.

Also virtual screen 3 sprite id keyb_input is created for the input text zone (this has been aded a few minutes ago and has not been tested a lot).

Also the demo has a few working buttons created with ZONES library, so this demo is for ZONES lib, IMPUT$() and SCALE  =D

The whole libe has been updated to use gensprite() and genfont() so you dont have to worry more about sprites IDs. Notice you still have to create a virtual screen ID 1 as your main drawing screen. Virtual screens 2 and 3 are also created and discarded after use.

Keyboard zones are moved from 1-44 to 10001-10044, so it is unlikely they will overwrite your current zones.

Now the keyboard is hidden if the user click outside the keyboard. Much cooler now! :)



[attachment deleted by admin]
Title: Re: IMPUT$ (input$ in any device!)
Post by: Kitty Hello on 2011-Sep-19
please fix it to use GENSPRITE instead. It's easier to "plug into" an existing project, then.

[edit]
AWESOME WORK!
Title: Re: IMPUT$ (input$ in any device!)
Post by: ampos on 2011-Sep-19
Oh, I see. I will rewrite it tonite. Stay tuned!  =D
Title: Re: IMPUT$ (input$ in any device!)
Post by: Minion on 2011-Sep-19
Its nice, I like it. But I have a problem with the space entry. Each time I click the space buttone it changes case, so if I enter 2 or more spaces it goes Upeper, then lower then upper then lower etc case.
Title: Re: IMPUT$ (input$ in any device!)
Post by: ampos on 2011-Sep-19
It is because I use it to write names of persons.

Just remove completly the cases 39 and 40.

I have just noted that this auto-case is not working in phisical keyboard :)
Title: Re: IMPUT$ (input$ in any device!)
Post by: msx on 2011-Sep-19
 :nw: :nw:
Title: Re: IMPUT$ (input$ in any device!)
Post by: Nathan on 2011-Sep-19
Superb work there.   :good:
Title: Re: IMPUT$ (input$ in any device!)
Post by: Albert on 2011-Sep-19
I like it. Should be add a Hide Keyboard button (or hide it if touch outside the keyboard)
Title: Re: IMPUT$ (input$ in any device!)
Post by: ampos on 2011-Sep-19
I like it. Should be add a Hide Keyboard button (or hide it if touch outside the keyboard)

Not bad idea to hide it.

It will be done.
Title: Re: IMPUT$ (input$ in any device!)
Post by: bigsofty on 2011-Sep-19
This looks really good, well done!  =D
Title: Re: IMPUT$ (input$ in any device!)
Post by: blackway on 2011-Sep-19
Ampos, It's great !!!!!!
Thanks for share !!
I'll use it in my next game!  :good:
Cheers,
Title: Re: IMPUT$ (input$ in any device!)
Post by: ampos on 2011-Sep-20
Updated to use gensprite() and genfont() so they can be included in your proyect more easily.

Also it has been updated to hide the keyboard if the user clicks outside the virtual keyboard. Much cooler now!

 :booze:
Title: Re: IMPUT$ (input$ in any device!)
Post by: Hatonastick on 2011-Nov-01
I love how this looks on my PC, however I can't get it to work properly on either of my Android devices.  It compiles, installs and runs.  However when you run the example the font is _tiny_.  At a guess I'd say around 2x2 pixels on the screen and it doesn't seem to matter whether I compile it for my phone (3" screen) or tablet (7" screen).  I've tried all sorts of changes but nothing seems to really impact on the size.  Both the 'small' font and the 'large' font seem to display as being the same size ie. tiny.  I'm guessing there's a scaling issue somewhere but I haven't spotted it thus far.

Has anyone had any luck getting this to work properly under Android?  I'd really like to use it. :)
Title: Re: IMPUT$ (input$ in any device!)
Post by: Mikele on 2011-Nov-01
[...]

Has anyone had any luck getting this to work properly under Android?  I'd really like to use it. :)

Hey, I had same problem. Try to change:

mpat$=GETCURRENTDIR$()+"media/"


to

mpat$="Media/"

In my case it does work.

M.

[EDIT] It's a "case sensitive" problem. I've changed line mpat$=GETCURRENTDIR$()+"Media/"  ("media" changed to "Media") and it does job as should.
Title: Re: IMPUT$ (input$ in any device!)
Post by: Hatonastick on 2011-Nov-01
Whoops, yeah I somehow missed that bit.  You are right, that's all that needs to be changed and then it works perfectly.  :good:

Thanks!
Title: Re: IMPUT$ (input$ in any device!)
Post by: chve on 2011-Dec-08
I have  just tested in win7  x64 and it is ver usefull!!  :enc: :enc: :enc:

(Added to my teasure code hihi)  :booze:
Thank you very much ampost  :)
Title: Re: IMPUT$ (input$ in any device!)
Post by: Dabz on 2011-Dec-18
Nice work, just a little thing though, pressing a space on the keyboard puts caps on?

EDIT: Ah, just spied the comments and removed the little snippets that does that! :)

Dabz