OnKeyUp in XML

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
agitated
GamingTools Subscriber
Posts: 30
Joined: Sat Apr 28, 2007 5:05 pm

OnKeyUp in XML

Post by agitated » Tue Feb 05, 2008 5:11 pm

I have a small LavishGUI in XML that contains a Textentry element.

I'd like to have the typed text relayed to a session when the Enter key is pressed.

The wiki says to define a string variable 'Key' with the name of the key needed, so I have that variable set to 'Enter', as listed in the bind -keylist output. It resides in an ISS file that does nothing more than load the UI and set the variable, then wait for queued commands.

Whenever I type in the textentry, any key being released relays the text instead of waiting for enter.

Here's the XML:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?> 
<ISUI> 
   <Window name='Chat'> 
      <Title>Chat</Title> 
      <X>300</X> 
      <Y>300</Y> 
      <Width>300</Width> 
      <Height>35</Height> 
      <Children> 
       
             <Textentry Name='Msg'>
	     <X>3</X>
	     <Y>3</Y>
	     <Width>100%</Width>
	     <Height>90%</Height>
	     <Color>FFDDBB00</Color>
	     <MaxLength>100</MaxLength>
	     <OnKeyUp>
		relay is2 EQ2Execute $&#123;This.Text&#125;
		This&#58;SetText[""]
	     </OnKeyUp>
             </Textentry>
      </Children> 
   </Window> 
</ISUI>
What am I doing wrong?

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Tue Feb 05, 2008 5:48 pm

You're misunderstanding the wiki.
* OnKeyUp

Executes when a key is released. A string variable "Key" contains the name of the key as defined by the keyboard driver.

* OnKeyDown

Executes when a key is pressed. A string variable "Key" contains the name of the key as defined by the keyboard driver.
What it's actually saying is that within OnKeyUp or OnKeyDown, there *is* a string variable "Key", which contains the name of the key that is going up or down.

I believe what you were intending to do is:

Code: Select all

        <OnKeyUp>
if $&#123;Key.Equal[Enter]&#125;
&#123;
      relay is2 EQ2Execute $&#123;This.Text&#125;
      This&#58;SetText[""]
&#125;
        </OnKeyUp> 
To help you understand what's going on.. OnKeyUp written in LavishScript looks just like this (in an objectdef, which in this case is your Textentry object):

Code: Select all

method OnKeyUp&#40;string Key&#41;
&#123;
; ----- contents of <OnKeyUp> here!
&#125;
or precisely in this case:

Code: Select all

method OnKeyUp&#40;string Key&#41;
&#123;
  if $&#123;Key.Equal[Enter]&#125;
  &#123;
        relay is2 EQ2Execute $&#123;This.Text&#125;
        This&#58;SetText[""]
  &#125;
&#125;
Hope that clears it up for you

agitated
GamingTools Subscriber
Posts: 30
Joined: Sat Apr 28, 2007 5:05 pm

Post by agitated » Tue Feb 05, 2008 6:52 pm

Yep, that clears it up and works perfectly.

Once again, thank you Lax :D

Post Reply