Hi!
As the title says, I want to focus the chat input field when I press enter, and send if I press enter again. What is the best way to achieve this?
Hi!
As the title says, I want to focus the chat input field when I press enter, and send if I press enter again. What is the best way to achieve this?
I guess the simplest way would be to put an event listener for Enter key, then check if text field is focused…
If you are using the ChatBox or ChatBoxExt,
to set the return key:
[java]
chatWindow.setSendKey(KeyInput.KEY_RETURN);
[/java]
For setting the foocus… I did something like this:
[java]
if (name.equals(“ChatFocus”) || name.equals(“SlashChatFocus”) && !isPressed) {
if (!app.getChatWindow().getChatInput().getHasFocus()) {
if (name.equals(“SlashChatFocus”))
app.getChatWindow().getChatInput().setText("/");
app.getGUIScreen().forceEventElement(app.getChatWindow().getChatInput());
app.getChatWindow().getChatInput().setHasFocus(true);
} else {
app.getChatWindow().getChatInput().setText("");
app.getChatWindow().getChatInput().resetTabFocus();
app.getGUIScreen().resetTabFocusElement();
app.getChatWindow().getChatInput().setHasFocus(false);
}
}
[/java]
This looks for both KEY_RETURN and slash to set focus
This also removes focus after sending a message. Soooo…
EDIT: There are a lot of redundant clear calls for focus just to ensure it is reset properly. They are probably not necessary, however… better safe than sorry
Ok! Thanks!