Support for native.newTextField

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.

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?

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

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

If I press the “Ü” Button on a german QWERTZKeyboard, 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.
 

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.

Hi guys,
it’s me again :wink:

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

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.  :slight_smile:
 
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!
 

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! :smiley:

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?

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.

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?

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

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

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.

@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 **

https://www.youtube.com/watch?v=MkDse2Pnac4&feature=youtu.be

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! 

Hello,

Where can I download the lib?

Thank you

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/

@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. 

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

https://www.youtube.com/watch?v=sPIiMMSb_9E

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* 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. \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

[sharedmedia=core:attachments:4193]