AS3 TextInput into TextField - message

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)
}

Related

Change the state of keyboard toolbar's button

I've been looking around and digging into my code without success so far so I'm asking here.
I added two buttons to a textField's keyboard as such :
emailTextField.addRightLeftOnKeyboardWithTarget(self, leftButtonTitle: "action_dismiss".localized, rightButtonTitle: "action_send".localized, leftButtonAction: #selector(dismissEmailTextFieldKeyboard), rightButtonAction: #selector(didTabSendButton))
This textfield is where the user enters his email. I already have a predicate that checks the validity of the email typed in by the user. That serves as an interaction enabler/disabler for my main send button.
I made a shortcut send button on the keyboard for UX purposes, and I would like it to be subjected to the predicate and to be disabled until the email typed in is correct.
So here is my issue, I do not find a way to access the keyboard's toolbar's buttons as properties in order to disable their interaction. Could anyone point me to the right direction please ?
Thanks in advance

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.

Get keyboard show event in Unity3d

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.

Disabling enter button in iOS keyboard

I have an iOS keyboard question.
Say we have a UITextField (let's call it textfield) and a standard virtual keyboard, with the Enter key set to Send. We'd like to disable the Send key when UITextField is empty, otherwise enable it. We have set enablesReturnKeyAutomatically to YES on the text field. This works fine when we manually edit the text in the text field.
However, the Send key doesn't seem to work fine when we programmatically change the text. Our app will clear the text field by calling textfield.text = #"" once the Send key is hit and the text is sent. In this case, we expect the Send key to be disabled since textfield's content is empty. But no -- it appears enabled.
We want to disable the Send key in such a case. Please share your experience if possible.
Thanks!
I think the best you can do is to ignore the return event this way:
- (BOOL) textFieldShouldReturn:(UITextField*) textField {
return textField.text.length > 0;
}

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.

Resources