So I have a web based game, and recently converted some of the GUI to use windows. It was pretty straight forward to get them working, and I had found a snippet in the forums about using GetNameOfFocusedControl in combination with Event driven input to do things like - only accept enter for a chat message when the chat text field in the chat window had focus. Dropping this in resulted in perfection. Then I went home over the weekend and for fun tried my game from their on a windows machine, I tried with IE and Firefox, and the enter key was no longer being registered and I couldn’t use my chat. Here is the code in the chat window:
// Make the contents of the chat window
private void DoChatWindow(int hwnd)
{
// I have a bool to identify a minimized/closed chat window or the full thing
// this button will "Close" the chat window.
if( GUI.Button(new Rect(380, 0, 20, 17), "X") )
m_bChatWindowOpen = false;
// Name the chat input control
GUI.SetNextControlName("ChatInput");
m_ChatMessage = GUI.TextField(new Rect(0, 190, 400, 20), m_ChatMessage, 512);
GUI.SetNextControlName("");
// Show the last 11 chat messages
// from the message log.
int chaty = 165;
int chatcount = 0;
if( m_ChatMessages.Count > 0 )
{
for(int i = m_ChatMessages.Count; i > 0; i--)
{
GUI.Label (new Rect (5, chaty, 390, 20), (string)m_ChatMessages[i-1]);
chaty-=15;
chatcount++;
if(chatcount > 10)
break;
}
}
// Now check for the enter key
if(GUI.GetNameOfFocusedControl() == "ChatInput")
{
if(Event.current.Equals(Event.KeyboardEvent("return")))
{
if(m_ChatMessage.Length > 0)
{
// Send the message to other clients
SendChatMessage(m_pLocalClient);
m_ChatMessage = "";
}
}
}
}
Again, this code works just fine on Mac in Safari or Firefox, but not at home on my windows machine. Is this a known issue? Is there something wrong with my code?