Page 1 of 1

[14 Sep 2009] In case of OnKeyUp

Posted: Sat Jun 13, 2020 5:32 pm
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


[14 Sep 2009] Re: In case of OnKeyUp

Posted: Sat Jun 13, 2020 5:32 pm
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"

[14 Sep 2009] Re: In case of OnKeyUp

Posted: Sat Jun 13, 2020 5:32 pm
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.

[14 Sep 2009] Re: In case of OnKeyUp

Posted: Sat Jun 13, 2020 5:32 pm
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

[14 Sep 2009] Re: In case of OnKeyUp

Posted: Sat Jun 13, 2020 5:32 pm
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!

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

Posted: Sat Jun 13, 2020 5:32 pm
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 :)