Menu key event detection

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm
Contact:

Menu key event detection

Post by dodopod »

I have code like this:

Code: Select all

class MyMenu : GenericMenu
{
    override bool OnUIEvent(UIEvent ev)
    {
        if (ev.type == UIEvent.Type_KeyDown)
        {
            Console.Printf("%s key pressed", ev.keyString);
        }
        else if (ev.type == UIEvent.Type_KeyUp)
        {
            Console.Printf("%s key released", ev.keyString);
        }
        else if (ev.type == UIEvent.Type_Char)
        {
            Console.Printf("%s entered", ev.keyString);
        }

        return Super.OnUIEvent(ev);
    }
}
I notice that certain keys (e.g. Enter, Page Up, Page Down) aren't detected. They do seem to get sent to MenuEvent (though it's only Char events for directional keys and KeyDown events for Enter and Escape), but is there any way to get OnUIEvent to recognize them?
Last edited by dodopod on Sat Dec 14, 2019 11:36 am, edited 1 time in total.
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm
Contact:

Re: Menu key event detection

Post by dodopod »

I don't think there's anything I can do with those enums that would work. I understand that, for non-printable characters, the key that was pressed would be an ESpecialGuiKeys value stored in keyChar, and that keyString would be empty. But I should still get something like this in the console:

Code: Select all

 key pressed
 entered
 key released
If I press Shift or Ctrl, that's exactly what happens, but for Enter, the cursor keys, Backspace, etc. I get nothing at all.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49223
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Menu key event detection

Post by Graf Zahl »

That's because the menu uses these keys, they never reach the event handler.
What are you trying to do here?
dodopod
Posts: 66
Joined: Wed Oct 04, 2017 2:00 pm
Contact:

Re: Menu key event detection

Post by dodopod »

My goal is to create a GUI API along the lines of Z-Windows or ZGUI. The menu is supposed to contain a root window, that contains other windows, etc. and keyboard events are supposed to be passed down from the parent to the active child. If one of the leaf windows is a text field, then it should be able to receive Enter and Backspace key presses, and the like.
Post Reply

Return to “Scripting”