Get keyboard show event in Unity3d - ios

I am making a game in unity3d for iPad only.
In one screen I need to take text input from user and for that I use Input Field.
I need to make some UI change when user open keyboard by taping Input Field. For that I need keyboard open(show) event. Input Field give me just two event 1. Text Change 2. Lost Focus. But I need get Focus event.
I read official document but can't find any relevant event. I search on internet for event, I get keystroke event but I need keyboard open event before user start typing.
In native iOS app we use UITextFieldDelegate Method - (void)textFieldDidBeginEditing:(UITextField *)textFieldor UIKeyboardDidShowNotification. Is there any way in Unity3d to get this kind of behaviour.

For input field with the new UI there is an isFocused variable.
http://docs.unity3d.com/ScriptReference/UI.InputField.html
http://docs.unity3d.com/ScriptReference/UI.InputField-isFocused.html
#pragma strict
// Required when Using UI elements.
public class Example {
public var mainInputField;
function Update() {
//If the input field is focused, change its color to green.
if (mainInputField.GetComponent.<InputField>().isFocused == true) {
mainInputField.GetComponent.<Image>().color = Color.green;
}
}
}
So if your field gets focused and it returns true you can execute some code. That is, if I understand you correctly.

I can't find anything that lets you know the InputField has been selected but a workaround may be setting the Interactable property to false and having an 'Edit' button near the field. When the 'Edit' button is pressed, you can change the UI elements and set the InputField.interactable = true.

Related

Xcode swift : connection from buttons to Text Fields

I am new to swift programming and Xcode
However I am creating a dart counter app but having trouble connecting the buttons to Text fields
I have buttons numbered 0-20 on the main story board and three text fields (one for each dart) how do I connect the buttons to the UITextFields - I can’t figure this out
Thanks
Based on my understanding of your issue, you actually need to connect the buttons to the text field in code. There is not going to be a simple way to do this in the interface builder. What you are looking for is to have some action happen when the user presses a number, and this may be added to the current value in the text field.
Create a function that handles any number button being pressed.
#IBAction func buttonPress(sender: UIButton) {
print(sender.tag)
//TODO: process the button based on its tag
}
Update all of the buttons in interface builder to have a tag value according to their number. This will let you handle them all in the same function (above) and differentiate between them.
Update the TODO block to handle the action appropriately. I would start by adding a variable to keep track of which dart number you are on, and using a switch statement to handle putting the value in the appropriate dart text box.
So there is always a current text field. Maintain an instance property that points to it. When the user taps a number, use that instance property to enter that value in that text field. When the user taps Enter, change the instance property to point to the next text field.

Dynamically change keyboard's return button but preserve type

I have an input field the user needs to fill with an alphanumeric code. The keyboard the user uses to type the code has a dynamic return button that changes to "send" as he writes some text on the field. When the field is empty the return button has the default value.
To dynamically change the return button type I use the following code:
if([textField.text isEqualToString:#""])
{
textField.returnKeyType = UIReturnKeyDefault;
}
else
{
textField.returnKeyType = UIReturnKeySend;
}
[textField reloadInputViews];
However this has the following drawback: since the code is alphanumeric, the user may be typing numbers, and yet the keyboard will always switch back to the letter keyboard, so to type more than one number in a row he will need to be continuously switching to number keyboard.
Is there any way to dynamically change the return key of a keyboard as the user types but to preserve the keyboard state to letters or numbers keyboard?
I think this is not a bug on Apple's side, more a missing implementation of API for the keyboard. With the new iOS8 API you might want to create your own keyboard returning the UIKeyboardType.
For iOS7 I worked around by inspecting the views of the keyboard. Use the US2KeyboardType CocoaPod or the source:
https://github.com/ustwo/US2KeyboardType
As Martin noted above, it's not a bug on Apple's side, but on my side. However I'll be posting the solution I've found since it is the one that solves that particular problem:
Instead of manually changing the return key type when there is text on the text field, Apple provides us with a property called enablesReturnKeyAutomatically that when set to YES it automatically manages the issue, enabling and disabling the return key depending on whether there is text or not in the text field.
Therefore you don't need to modify the returnKeyType property, and thus, no calling to reloadInputViews is required, so the keyboard doesn't change back to its original state.

combobox steal keyboard from main window in pyqt

I'm writing a small pyqt program. I want the main window to to react to arrow movement. I added an event to my MainGui class, keyPressEvent, that handle this. The event work fine as long as I don't press certain buttons such as Key_Up or Key_Down are directed to my (currently only) QComboBox and not to my mainGui. I tried to give the focus to mainGui after each paintEvent but then I need to double click on buttons/comboBox.
Then I tried to use the MousePressEvent to check if a certain element is under the mouse. This work fine with the comboBox, but not with the button.
So, how can I direct key events to the mainGui or give the focus to QButtons?
I used eventFilter to identify when the mouse enter the QPushButton and give it focus:
def eventFilter(self,source,event):
if event.type() == QtCore.QEvent.HoverMove:
if self.execButton.underMouse():
self.execButton.setFocus()
self.keepFocus=False
else :
self.keepFocus=True
keepFocus is a flag I initialized in the __init__ function of the class. I added this part at the paintEvent function
if self.keepFocus:
self.setFocus()
else:
self.keepFocus = True
Now, I keep the focus at the MainGui and I only give it to the button when the mouse hove over it. If I do another action (like pressing a mouse button or a keyboard key) the focus is given back to the MainGui. This will create some buggy filling (For example, I need to press twice a keyboard key before the first response) but this is workable.

AS3 TextInput into TextField

I am creating a small chat application. I want to edit a message in a TextInput field and when the user hit's Enter on the Keyboard the message will be transferred from the TextInput over to the TextArea. How do I do this?
Thank You
You will need to add an event listener to the keyboard events see here
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/events/KeyboardEvent.html#keyCode
Enter will have a specific keyboard code on the event you can right logic for eg;
addEventListener(KeyboardEvent.KEY_DOWN, handleKeyboard);
function handleKeyboard(e:KeyboardEvent):void
{
// eg if (e.keycode == //the code for enter )
{
//your chat send message logic
}
//of course find the different keycodes easily by trace(e.keycode)
}

Getting values out of text fields with UIAutomation

I'm trying to understand how UIAutomation can be used to perform automatic application tests, so I've created a temperature converter app that can be driven from the JavaScript interface. Here's the UI:
The top text field has an Accessibility label of "Celsius", similarly the bottom field has "Fahrenheit" as its Accessibility label. I'm trying to drive it through this script:
UIALogger.logStart("Test -40ºC == -40ºF");
var window = UIATarget.localTarget().frontMostApp().mainWindow();
var celsiusField = window.textFields()["Celsius"];
var fahrenheitField = window.textFields()["Fahrenheit"];
var convertButton = window.buttons()["Convert"];
celsiusField.setValue("-40");
convertButton.tap();
var fahrenheitValue = fahrenheitField.value();
if (fahrenheitValue == "-40.0") {
UIALogger.logPass("-40C == -40F");
} else {
UIALogger.logFail("-40C == " + fahrenheitValue + "F");
}
This correctly sets the text in the Celsius field to "-40", and when the button is tapped, the app updates the text in the Fahrenheit field to "-40.0". However, fahrenheitValue has the value "Fahrenheit" (the name/label of the text field), so the test fails. I wondered whether this was maybe a timing issue, so put in a one-second delay after the tap, which didn't change the behaviour.
Is it possible to get the text out of the text field and compare it with the expected value?
Is it getting "Fahrenheit" because that's the accessibility label or because it's the placeholder text?
It looks like value() might return the placeholder text. One workaround could be to modify the placeholder value once the user starts typing to set it to be the text the user entered and then reverting it to Fahrenheit when they delete? I assume that even when you call setValue it acts as it would when the UITextField delegate methods get called?
You could add a label to your view, update it and read it out.
Try hooking up the Accessibility Inspector to show what UIAutomation "sees" in your app. It might be that it's reading some stale values because of the way you set the values in your app.
One way of refreshing the values is to send an update event:
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil);

Resources