Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Support for native.newTextField
Started by waldemar.krampetz Jun 26 2015 01:20 AM

47 replies to this topic
[TOPIC CONTROLS]
Page 1 of 2 1 2
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

waldemar.krampetz

[GLOBAL: userInfoPane.html]
waldemar.krampetz
  • Observer

  • 5 posts
  • Corona SDK

Hi,
great work so far. I had no problems building our game and it runs realy smooth and stable. There ist just one important thing missing: The support for text input through native.newTextField or native.newTextBox.

Whats the current plan about this? Is this on the roadmap? Are there any workarounds?

Thats a must have feature for our game. Without the possibility to get text input from the player, a windows version of our game would be useless.

Thanks



[TOPIC: post.html]
#2

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Using "native" Windows TextFields/TextBoxes in a Windows game is highly unusual.  Most games don't do it for a reason.  The main reason is that you can't render native Windows UI while a game is rendering fullscreen.  At least not without putting it into borderless maximized window mode, in which case, you can't take full advantage of the video card.  I suppose for a non-fullscreen app it would be fine if we can get OpenGL rendering to "clip" where the native UI is displayed at (prevents your game from rendering on top of the native UI).

 

In my opinion, for a Windows or Mac based game, I think it would be better to implement text input like how it works on consoles.  Just display a virtual keyboard that players can use for text entry.  You can use the up/down/left/right or letter key events.  For example...

   http://help.support.ubi.com/images/ACIV/ULC/ULCRedeemCode3602.png

 

And we're thinking that game controller support is the next high priority feature to implement on Windows.



[TOPIC: post.html]
#3

waldemar.krampetz

[GLOBAL: userInfoPane.html]
waldemar.krampetz
  • Observer

  • 5 posts
  • Corona SDK

Ok, maybe the topic is misleading. I don't realy need a support for "native" Windows textfields. I just need a way to get text input from the player.

For example the nickname in the Highscore, credentials for a Registration / Login form, or even the possibility to chat with other players. These are common features in a bigger multiplayer game.

A "console" like approach isn't really what we want. It's a bad user experience in a PC Game.

I could build my own textfields but the current properties of the "key" event aren't helpful. I dont't see any support for different keyboard layouts. Is it possible to get the pressed character?



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,394 posts
  • Enterprise

Have you looked at the KeyEvent's sample app?   https://github.com/coronalabs/samples-coronasdk/tree/master/Hardware/KeyEvents

(its also part of your SDK under SampleCode/Hardware/KeyEvents.)

 

When you press a letter on the keyboard, you get two events a "down" phase and and "up" phase. There isn't a reason you couldn't build your own input if needed. 

 

Rob



[TOPIC: post.html]
#5

waldemar.krampetz

[GLOBAL: userInfoPane.html]
waldemar.krampetz
  • Observer

  • 5 posts
  • Corona SDK

Hi Rob,
the problem with the "key" event is the missing support for different keyboard layouts.

If I press the "Ü" Button on a german QWERTZ Keyboard, this is what I get:
 

{
  descriptor = ";",
  isAltDown = false,
  isCommandDown = false,
  isCtrlDown = false,
  isShiftDown = false,
  keyName = ";",
  name = "key",
  nativeKeyCode = 186,
  phase = "up"
}

This isn't helpful at all. Our game will be localized in many different languages, so we need the support for different layouts and characters.
 



[TOPIC: post.html]
#6

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

We're not planning on adding text entry support in the near future.

Game controller support is our next highest priority feature.

 

I still recommend that you roll your own console-style text entry screens.  A lot of modern games that are ported between consoles and PC have them and gamers have learned to accept them.  Especially if the game supports game controllers.



[TOPIC: post.html]
#7

waldemar.krampetz

[GLOBAL: userInfoPane.html]
waldemar.krampetz
  • Observer

  • 5 posts
  • Corona SDK

Hi guys,
it's me again ;)

I have another question, what are the plans for the Enterprise version and the possibility to build our own plugins for win32 (native, not pure lua)?

Could this be a solution to build our own text input fields?

Thanks



[TOPIC: post.html]
#8

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

Corona Win32 apps supports plugins now via the newest daily builds.  We haven't announced it yet, but we were planning on doing so next week.  :)
 
First, any Win32 plugins available to the Windows version of the Corona Simulator will automatically be included in the Win32 app build.  For example, this includes the OpenSSL, Zip, and Bit plugins.  This also includes pure Lua based plugins as well, but I don't think we have any on the plugin store yet (the intent was to distribute shader plugins in this fashion).  Also, please note that the existing zip plugin has Win32 Unicode path issues, which turns out to be an issue with the 3rd party open source zlib library that it's currently using.  That might be a deal breaker for you.
 
Regarding making your own Win32 plugins, while we don't have any official documentation for it *yet*, it is absolutely possible to create them now.  The newest daily build of Corona Enterprise provides the Win32 *.lib files and *.h header files you need.
 
And the header files can be found under...
   CoronaEnterprise\Corona\shared\include
 
You can find the *.lib files under...
   CoronaEnterprise\Corona\win\lib
 
You'll need Visual Studio 2013 to create your plugin DLL.  I recommend using the free Community Edition provided that your organization meets its terms (ie: for example, it's not free for organization that make more than $1 million in revenue).  You'll need to do the following to create your plugin:

  • In Visual Studio, select "File\New" from the menu.
  • Select "Installed\Visual C++\Win32" in the tree on the left of the "New Project" window.
  • Select "Win32 Project" from the list in the middle.
  • For the "Name" field, enter a name such as "plugin.<YourLibraryName>".  Note that when you "require" in your library in Lua, it'll use this name.
  • After creating the project, right click on your project node in the "Solution Explorer" panel.
  • Select "Properties" from the popup menu.  (This part forward requires substantial knowledge of how to use VC++.)
  • Under "Linker\Input" add a dependency to "CoronaEnterprise\Corona\win\lib\CoronaLabs.Corona.Native.lib".  (This library is needed for the Corona C APIs.  It's up to you to set a good relative path.)
  • Under "Linker\Input" add a dependency to "CoronaEnterprise\Corona\win\lib\lua.lib".  (This library provides the standard Lua C APIs.  It's up to you to set a good relative path.)
  • Under "C/C++\General" add an "Additional Include Directories" path to "CoronaEnterprise\Corona\shared\include\Corona".  (This provides access to Corona C APIs.  It's up to you to set a good relative path.)
  • Under "C/C++\General" add an "Additional Include Directories" path to "CoronaEnterprise\Corona\shared\include\lua".  (This provides access to Lua's C APIs.  It's up to you to set a good relative path.)
  • Under "General", make sure to select "Platform Toolset" option "Visual Studio 2013 - Windows XP (v120_xp)".  This allows your plugin to run under Windows XP, if you still wish to support that platform.  Otherwise, your plugin can only be loaded on Windows Vista or newer OS versions.

The standard Lua library (not made by Corona Labs) has built-in support for loading DLLs via the Lua require() function.  It's documented on the www.lua.org website.  But here's a quick summary.  Your DLL needs to export a C function like this...

extern "C" __declspec(dllexport) int luaopen_plugin_<YourPluginName>(lua_State* L)

You can find an example on how this works via the link below.  It's our "bit" plugin that we've open sourced on gihub.

   https://github.com/coronalabs/plugins-source-bit

 

There's just one more thing to note.  We current haven't made our Win32 specific C APIs public yet since that's still in flux at the moment.  But we do plan on opening it up in the near future (no specific date yet).  If your plugin needs access to the main window's HWND and Window messages, and I suspect it does, then a simple solution to this would be to get a hold of the main window's HWND via Microsoft's GetActiveWindow() C function.  That's a safe assumption to make for a Win32 built app (but not a safe assumption in the Corona Simulator).

   https://msdn.microsoft.com/en-us/library/windows/desktop/ms646292(v=vs.85).aspx

 

Also, when you set your WindowProc callback to capture IME messages in your plugin, make sure to maintain the WindowProc *chain* by passing any messages your plugin doesn't handle to the previously set WindowProc callback (which would be Corona in this case).  Otherwise, your plugin will steal messages from the app, preventing Corona from receiving key and mouse message/events, and worse, the close message/event which allows the [x] button to close the app.

   https://msdn.microsoft.com/en-us/library/windows/desktop/ms644898(v=vs.85).aspx

 

Edit:  Final note.  Your compiled plugin DLL and all of its DLL dependencies (if any) will need to be copied to your app's root directory, where your *.exe all of Corona's DLLs are located.

 

I hope this helps!
 



[TOPIC: post.html]
#9

waldemar.krampetz

[GLOBAL: userInfoPane.html]
waldemar.krampetz
  • Observer

  • 5 posts
  • Corona SDK

Oh wow. These are awesome news! A big thanks for the guide, we will try it soon.

 

I think this will help us a lot! :D



[TOPIC: post.html]
#10

Glitch Games

[GLOBAL: userInfoPane.html]
Glitch Games
  • Contributor

  • 597 posts
  • Corona SDK

I know that you said that native text fields are basically not going to happen however I would just like put in our request for them.

 

We have a newsletter signup form in our adventure games, as well as puzzles that use text entry. For instance typing in a password on a computer or searching for something in a Glitch Search box. 

 

A virtual keyboard would be fine for a touch screen or a console, however I think it just seems strange that we would require that on a Windows machine that is basically guaranteed to be connected to a physical keyboard.

 

We've now got our adventure games working on the Mac builds, and the native keyboard works fine in there. Is there any chance for native text fields in the Win32 builds?



[TOPIC: post.html]
#11

Joshua Quick

[GLOBAL: userInfoPane.html]
Joshua Quick
  • Moderator

  • 3,397 posts
  • Corona Staff

The current plan is to implement game controller support next.  That's the next most hotly demanded feature.

 

If you only need to support English text input, then you can do what Rob suggested and use key events.  But you can really only support numbers and English letters with this technique.  It's not safe to assume what the shift key will do with the number and symbol keys because the character it'll produce will differ between different region keyboards.  For example, the $ sign will be above the 4 key on US English keyboards, but not on European keyboards (naturally).

 

If you need international text entry support, then perhaps you and @waldemar can work together on this.  I've already shown @waldemar how to make a Win32 plugin.



[TOPIC: post.html]
#12

Glitch Games

[GLOBAL: userInfoPane.html]
Glitch Games
  • Contributor

  • 597 posts
  • Corona SDK

For some parts we only need english text input but for others we need email address, so yea things get trickier for the latter. 

 

I don't particularly want to get into plugin dev right now, especially as I don't have a windows machine to work on.

 

@waldemar - are you expecting to be able to release a plugin?



[TOPIC: post.html]
#13

ubj3d.android

[GLOBAL: userInfoPane.html]
ubj3d.android
  • Contributor

  • 741 posts
  • Corona SDK

In most of our games we need text input (player name, password...).

 

Corona not supporting it for Windows and Mac is a huge disappointment.



[TOPIC: post.html]
#14

Perry Clarke

[GLOBAL: userInfoPane.html]
Perry Clarke
  • Moderator

  • 850 posts
  • Corona Staff

Not that it helps you a whole lot but native.newText() does work in OS X CoronaSDK apps.  OS X is an entirely different world graphics-wise and supports putting OS controls on top of OpenGL surfaces.



[TOPIC: post.html]
#15

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,605 posts
  • Corona SDK

@ubj3d.android & @waldemar.krampetz

 

I have a solution which is in beta (works well for me and one other).  If you're willing to use a beta product and give feedback, I'll give you a free copy.  Just e-mail me here:

 

Beta Now Closed - Follow the testing Progress here: https://forums.coronalabs.com/topic/58141-nativenewtextfield-for-windows/

 

** ADDED NEW VIDEO SHOWING placeholder AND isSecure SETTINGS WORKING **

 


Edited by roaminggamer, 24 July 2015 - 08:29 AM.


[TOPIC: post.html]
#16

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,605 posts
  • Corona SDK

Before you ask, this solution detects which system it is on and uses the real-deal if it is available.  i.e. It fakes it on Windows, but you get actual native.newTextField() objects on all other systems.  Code once in other words.



[TOPIC: post.html]
#17

ubj3d.android

[GLOBAL: userInfoPane.html]
ubj3d.android
  • Contributor

  • 741 posts
  • Corona SDK

Before you ask, this solution detects which system it is on and uses the real-deal if it is available.  i.e. It fakes it on Windows, but you get actual native.newTextField() objects on all other systems.  Code once in other words.

 

Great! 



[TOPIC: post.html]
#18

IronMan

[GLOBAL: userInfoPane.html]
IronMan
  • Enthusiast

  • 83 posts
  • Corona SDK

@ubj3d.android & @waldemar.krampetz

 

I have a solution which is in beta (works well for me and one other).  If you're willing to use a beta product and give feedback, I'll give you a free copy.  Just e-mail me here:

 

Beta Now Closed - Follow the testing Progress here: https://forums.coronalabs.com/topic/58141-nativenewtextfield-for-windows/

 

** ADDED NEW VIDEO SHOWING placeholder AND isSecure SETTINGS WORKING **

 

 

Hello,

 

Where can I download the lib?

 

Thank you



[TOPIC: post.html]
#19

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,605 posts
  • Corona SDK

This is not available to anyone but a few beta testers yet.

 

If you want to follow the progress on this lib check this post occasionally:

 

 https://forums.coronalabs.com/topic/58141-nativenewtextfield-for-windows/



[TOPIC: post.html]
#20

john.armstrong

[GLOBAL: userInfoPane.html]
john.armstrong
  • Contributor

  • 136 posts
  • Corona SDK

@roaminggamer,

 

Will you please email me the beta textfield. This is a feature that we need right away for a business app. I tried to message you but it said you cannot receive messages. 



[TOPIC: post.html]
#21

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 468 posts
  • Corona SDK

It's funny that this thread has popped up when it did, as I just last week started working on a module to add "faked" support for native.newTextField() and native.newTextBox() in the Windows simulator. Ed and I have corresponded on this, and it seems like he and I are taking slightly different approaches to the problem, so with his blessing (I didn't want to steal anybody's thunder or step on toes), I'm going to make my own solution available here, and on my website later this week, once I have time to compose a blog post around it.
 
There is a sample project that shows off the various methods and parameters you can apply or adjust to native text inputs attached to this post. You can load that up in the simulator to check it out, or if you want, just copy "windowsText.lua" from that sample project folder and require it into your own project.
 
The module is only lightly commented, but there is a "how to" section at the top of it. I've copied that text at the bottom of this post. The module is set up to overwrite the default native.newTextField() and native.newTextBox() APIs, so you don't need to change any of your code to use it. If you are running in the Windows simulator, it'll use the faked APIs - if you are running it on any other platform, it'll use the native versions. But you can override this behavior by calling windowsText.enable() to force the faked versions on a non-Windows platform, and windowsText.disable() to revert back to the native APIs. The faked text input objects dispatch "userInput" events identical to those put out by their native counterparts, so if you have event listeners for your input fields, they'll work just fine.
 
I probably won't be doing too much support for this module, as it's not something that would be used in a released app (it's just a tool to enable text input in the simulator, after all), but if you find any bugs please let me know and I'll do my best to fix them. In my testing, it works pretty much as advertised, though. Hope some of you find it useful!
 
-Jason
 
 
************************************************************************************
windowsText module for Corona SDK
Copyright (c) 2015 Jason Schroeder
http://www.jasonschroeder.com
http://www.twitter.com/schroederapps
************************************************************************************

ABOUT THE MODULE:
This module was created to "fake" native text input on the Corona Simulator
for Windows, which as of July 2015 does not support the native.newTextBox() and
native.newTextField() APIs. You are welcome to modify it as needed, but
it is set up to "just work" by requiring it into your Corona project. Once required,
the module will check to see if the project is running in the Windows simulator,
and if it is, it will overwrite native.newTextBox() and native.newTextField()
with these non-native Windows simulator-compatible functions. These modified functions
are fully compatible with all syntax and methods of their native counterparts,
so you will not need to alter your code at all to support them.

************************************************************************************

HOW TO USE THE MODULE:

1.) Place windowsText.lua (this file) in your project's root directory
(where your main.lua resides)

2.) Require the module by placing the following code in your main.lua:
local windowsText = require("windowsText")

3.) That's it! Calling native.newTextField() or native.newTextBox() will now
work in the Windows Simulator just like it does on-device or in OS X.

4.) If you want to use these non-native textFields or textBoxes outside the
Windows simulator, you can optionally call windowsText.enable() to overwrite
the native functions. You can revert back to the native APIs by calling
windowsText.disable() if you wish.

************************************************************************************

Attached File  windowsText.zip   253.04KB   35 downloads

Attached Files



[TOPIC: post.html]
#22

john.armstrong

[GLOBAL: userInfoPane.html]
john.armstrong
  • Contributor

  • 136 posts
  • Corona SDK

This is so awesome.. I made one quite similar last night. The only thing different that I am trying to implement is to slide the text to stay in view when it goes near the end for a single line textbox.



[TOPIC: post.html]
#23

conor1

[GLOBAL: userInfoPane.html]
conor1
  • Contributor

  • 166 posts
  • Corona SDK

This is very interesting, but I'm missing something. Running in build 2689 on windows, I can see the text field and textbox in your example, adjust them, but can't type into them.



[TOPIC: post.html]
#24

schroederapps

[GLOBAL: userInfoPane.html]
schroederapps
  • Contributor

  • 468 posts
  • Corona SDK

Hi Conor, I was running build # 2689 in the demo video, so I know it works in that version of the Windows simulator. I know this sounds silly, but you are clicking on the textfield itself before trying to type, right? Just like native text fields and boxes on OS X, you have to click the text field prior to typing into it. A light blue border will appear around it when it is "clicked into."

 

Also, are you using a US English keyboard? One limitation of this method of collecting input is that different keyboards would need to be accounted for, and by default, I only included support for a US English keyboard. You can add your own by creating a table of input values for a non-English keyboard (if you are using one). Just look at the structure of the "US_English" table in the module and use it as a template.

 

Let me know if any of the above helps you out. Thanks!



[TOPIC: post.html]
#25

conor1

[GLOBAL: userInfoPane.html]
conor1
  • Contributor

  • 166 posts
  • Corona SDK

In your example, no light blue box appears. But when I implement it in my project, that box appears when I click it. But there's no text input. I'm using a default text for the box, so it's not empty at the start. Would that effect it?

 

I'm not using US_English, but I'm guessing that would only result in some different input results?




[topic_controls]
Page 1 of 2 1 2
 
[/topic_controls]