Need more control over the touchscreen keyboard
On Android and iOS, when a textbox gets focus then the touchscreen keyboard is opened automatically.
However I need more control over this touchscreen keyboard:
* When the textbox is for an email address, the specific email keyboard should open (with the '@' key).
* I would like to disable the 'text preview'.
I see how I can do this in Unity (http://docs.unity3d.com/Manual/MobileKe ... ml#Android). However I don't see how I can wire this up in NoesisGUI.
The correct point to look at seems to be "NoesisGUISystem.OverrideDefaultSoftwareKeyboardCallbacks()", however I don't know how I can get a reference to the NoesisGUISystem instance.
What would be the recommended approach here?
Kristof
However I need more control over this touchscreen keyboard:
* When the textbox is for an email address, the specific email keyboard should open (with the '@' key).
* I would like to disable the 'text preview'.
I see how I can do this in Unity (http://docs.unity3d.com/Manual/MobileKe ... ml#Android). However I don't see how I can wire this up in NoesisGUI.
The correct point to look at seems to be "NoesisGUISystem.OverrideDefaultSoftwareKeyboardCallbacks()", however I don't know how I can get a reference to the NoesisGUISystem instance.
What would be the recommended approach here?
Kristof
Last edited by Kristof on 12 Jun 2014, 10:53, edited 1 time in total.
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Need more control over the touchscreen keyboard
Yes, the way to have more control over the software keyboard is overriding the default behaviour by providing your own callbacks.
You can get the instance this way:
Or just modify the NoesisGUISystem.cs script and add a new static property to make the instance public:
We will add this for the following release to make things easier.
You can get the instance this way:
Code: Select all
GameObject go = GameObject.Find("NoesisGUISystem");
NoesisGUISystem noesisGUI = go.GetComponent<NoesisGUISystem>();
Code: Select all
public static NoesisGUISystem Instance
{
get { return _instance; }
}
Re: Need more control over the touchscreen keyboard
I've implemented your second solution and it indeed does the trick. Thanks a lot!
Re: Need more control over the touchscreen keyboard
While at first the proposed solution seemed to solve my problem, I still can't get the functionality that I want.
I have made a helper-class to display the touch-keyboard. This class has exactly the same functionality as the NoesisGUISystem class relating to the keyboard. The idea is that I will extend this class to support more functionality (e.g. showing a keyboard for email addresses).
However this helper-class does not work (although it contains the same functionality as NoesisGUISystem):
[*] Whatever text is typed in the keyboard is not copied into the textbox
[*] From some logging I have found out that the 'text' property of the keyboard is always null.
[*] When the keyboard is closed, it always reopens automatically
I've added my code below. Does anybody have an idea of what I am doing wrong here?
I have made a helper-class to display the touch-keyboard. This class has exactly the same functionality as the NoesisGUISystem class relating to the keyboard. The idea is that I will extend this class to support more functionality (e.g. showing a keyboard for email addresses).
However this helper-class does not work (although it contains the same functionality as NoesisGUISystem):
[*] Whatever text is typed in the keyboard is not copied into the textbox
[*] From some logging I have found out that the 'text' property of the keyboard is always null.
[*] When the keyboard is closed, it always reopens automatically
I've added my code below. Does anybody have an idea of what I am doing wrong here?
Code: Select all
class TouchKeyboardHelper : MonoBehaviour
{
public void Start()
{
NoesisGUISystem.Instance.OverrideDefaultSoftwareKeyboardCallbacks(ShowSoftwareKeyboard, HideSoftwareKeyboard);
}
private Noesis.Control _focusedElement = null;
private TouchScreenKeyboard _keyboard = null;
private bool _keyboardActivated = false;
private void ShowSoftwareKeyboard(UIElement focusedElement)
{
if (focusedElement != null)
{
var tb = focusedElement.As<Noesis.TextBox>();
if (tb != null)
{
_focusedElement = tb;
_keyboard = TouchScreenKeyboard.Open(tb.GetText());
}
else
{
var pb = focusedElement.As<Noesis.PasswordBox>();
if (pb != null)
{
_focusedElement = pb;
_keyboard = TouchScreenKeyboard.Open(pb.GetPassword(),
TouchScreenKeyboardType.Default, false, false, true);
}
}
}
}
private void HideSoftwareKeyboard()
{
if (_keyboard != null)
{
// TODO: Force software keyboard to hide
_focusedElement = null;
_keyboard = null;
}
}
public void Update()
{
UpdateText();
}
private void UpdateText()
{
if (_focusedElement != null && _keyboard != null)
{
if (_keyboard.active)
{
_keyboardActivated = true;
var tb = _focusedElement.As<Noesis.TextBox>();
if (tb != null)
{
tb.SetText(_keyboard.text);
}
else
{
var pb = _focusedElement.As<Noesis.PasswordBox>();
pb.SetPassword(_keyboard.text);
}
}
if (_keyboardActivated)
{
if (_keyboard.done || _keyboard.wasCanceled)
{
_keyboardActivated = false;
// Remove focus from the text box
_focusedElement.GetKeyboard().Focus(null);
}
}
}
}
}
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Need more control over the touchscreen keyboard
I found the source of all the problems you described. NoesisGUISystem exposes the IsSoftwareKeyboardActive property that is used by NoesisGUIPanel to update the focus of the application when OnApplicationFocus message is received.
If you take a look at the implementation of IsSoftwareKeyboardActive property, it relies on the _keyboard member variable, that is not modified if you override the default software keyboard callbacks.
To solve it, modify that property to something like this:
And update this property when software keyboard is shown and hidden.
We have to simplify this code to make it easier for users to override the default behavior. We'll try to improve it for the next version.
If you take a look at the implementation of IsSoftwareKeyboardActive property, it relies on the _keyboard member variable, that is not modified if you override the default software keyboard callbacks.
To solve it, modify that property to something like this:
Code: Select all
#if !UNITY_STANDALONE
private bool _keyboardActive = false;
#endif
public static bool IsSoftwareKeyboardActive
{
get
{
#if !UNITY_STANDALONE
if (_isInitialized)
{
return _instance._keyboardActive;
}
#endif
return false;
}
set
{
#if !UNITY_STANDALONE
if (_isInitialized)
{
_instance._keyboardActive = value;
}
#endif
}
}
Code: Select all
_keyboard = TouchScreenKeyboard.Open(tb.GetText());
NoesisGUISystem.IsSoftwareKeyboardActive = true;
Code: Select all
_keyboard = null;
NoesisGUISystem.IsSoftwareKeyboardActive = false;
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Need more control over the touchscreen keyboard
In the upcoming 1.1.9 version we are going to improve the way default software keyboard management can be overridden. We will expose a base SoftwareKeyboardManager that can be inherited to modify how TouchScreen keyboard is opened, or to override completely how software keyboard is managed. There will be more info in the 'First steps with NoesisGUI in Unity' tutorial.
-
-
sfernandez
Site Admin
- Posts: 2908
- Joined:
Re: Need more control over the touchscreen keyboard
Improvements done in current 1.1.9 version.
Take a look at the documentation (Software Keyboard section): http://www.noesisengine.com/docs/Gui.Co ... orial.html
Take a look at the documentation (Software Keyboard section): http://www.noesisengine.com/docs/Gui.Co ... orial.html
Re: Need more control over the touchscreen keyboard
Thanks, that's exactly what I need.
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests