[14 Sep 2009] In case of OnKeyUp

Contains all messages from the Hollywood mailing list between 01/2006 and 08/2012
Locked
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

[14 Sep 2009] In case of OnKeyUp

Post by lazi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Sep 2009 15:43:37 +0100

Hi!

Here is a bit of script that can show that OnKeyUp event not addressing every control key by its name. Instead of "SPACE" and "ENTER" I have to use ascii codes of these keys and change to Switch Asc(msg.key). What is the concept for such behaviour? I know that enter and space are displayable, so it has ascii codes, but IsKeyDown() can handle them by name. At least a bit of info in the guide would clarify the situation for newbies.

Code: Select all

Function p_key(msg)
    Switch msg.key
    Case "UP":
        Print("up")
        Case "DOWN":
            Print("down")
            Case "SPACE":
                Print("space")
                Case "ESC":
                    Print("esc")
                    Case "ENTER":
                        Print("enter")
                EndSwitch
            EndFunction

InstallEventHandler({Onkeyup=p_key})

Repeat
    WaitEvent
Forever

PEB
Posts: 568
Joined: Sun Feb 21, 2010 1:28 am

[14 Sep 2009] Re: In case of OnKeyUp

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Sep 2009 18:02:26 -0000

For SPACE you can use " " For ENTER you can use "/n"
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

[14 Sep 2009] Re: In case of OnKeyUp

Post by lazi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Sep 2009 22:15:29 +0200

Thanks Paul!

Tried it, but don't work, and not helps to make the script readable.
PEB
Posts: 568
Joined: Sun Feb 21, 2010 1:28 am

[14 Sep 2009] Re: In case of OnKeyUp

Post by PEB »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Sep 2009 21:09:13 -0000

The following code works for me:

Code: Select all

Function p_key(msg)
Switch msg.key
Case "UP":
Print("up")
Case "DOWN":
Print("down")
Case " ":
Print("space")
Case "ESC":
Print("esc")
Case "\n":
Print("enter")
EndSwitch
EndFunction

InstallEventHandler({Onkeyup=p_key})

Repeat
WaitEvent
Forever
User avatar
lazi
Posts: 625
Joined: Thu Feb 24, 2011 11:08 pm

[14 Sep 2009] Re: In case of OnKeyUp

Post by lazi »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Mon, 14 Sep 2009 23:56:41 +0200

Hello rev

Ok. This is really works, however in your last post there was a simple slash for \n.

Thanks!
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

[15 Sep 2009] Re: Re: In case of OnKeyUp

Post by airsoftsoftwair »

Note: This is an archived post that was originally sent to the Hollywood mailing list on Tue, 15 Sep 2009 00:37:32 +0200
Hello rev

Ok. This is really works, however in your last post there was a simple slash for \n.
The idea behind the different behaviours of IsKeyDown() and the event handler is to make certain tasks easier. Supposed that you do something like

Code: Select all

InstallEventHandler({OnKeyUp = Function(msg) Print(msg.key) EndFunction})
If msg.key would contain "SPACE" now for every space press, it would be pretty annoying. Same for RETURN, ENTER etc. Well, but it all depends on the circumstances of course. In your case it's probably the other way round :)
Locked