Author Topic: Simulate user input  (Read 5718 times)

0 Members and 2 Guests are viewing this topic.

Offline gumby

Simulate user input
« on: March 10, 2013, 12:23:20 PM »
I'm attempting to create events programatically (keypresses & mouse clicks) but not having any success.  

My thought is that this code should create a new mouse event where location (30,30) is left clicked which should move the ego to that location:
Code: [Select]
    (if(Said('look'))
            (= hEvent Event:new())

            (send hEvent:
                 type(evMOUSEBUTTON)
                 x(30)
                 y(30)
                 modifiers(512)    // 512 left click, 515 right click
                 claimed(FALSE)
            )
            
            (super:handleEvent(hEvent))
     )
But it's not working, nothing seems to happen.  I've got it placed in a template game in the Rm001 script.

Here's a simpler event that should fire a keyboard event (ALT-M) and trigger the easy-alt debugging that displays the available memory, but doesn't work either:
Code: [Select]
           (send hEvent:
                 type(evKEYBOARD)
                 message($3200)
                 claimed(FALSE)
            )

Is this even possible to do?  I suspect that I'm creating the event properly, but maybe the handleEvent call is incorrect?
« Last Edit: March 10, 2013, 12:35:10 PM by gumby »


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline gumby

Re: Simulate user input
« Reply #1 on: March 10, 2013, 01:10:08 PM »
Well, I figured it out for mouse events:

Code: [Select]
           (= myEvent Event:new())
            
            (send myEvent:
                 type(evMOUSEBUTTON)
                 x(30)
                 y(30)
                 modifiers(512)    // 512 left click, 515 right click
                 claimed(FALSE)
            )

            (send gEgo:handleEvent(myEvent))
            (send myEvent:dispose())

I had to change it so that the ego event handler processed the event.  Haven't got keyboard events working yet.

EDIT:  Keyboard events work too, just call a different event handler.
Code: [Select]
           (= myEvent Event:new())

            (send myEvent:
                 type(evKEYBOARD)
                 message($3200)
                 claimed(FALSE)
            )
            (send gGame:handleEvent(myEvent))
            (send myEvent:dispose())

Makes sense now, I just needed to send the events to the correct objects.  Oh yeah, and we need to remember to dispose of our event when we are done
« Last Edit: March 10, 2013, 01:17:04 PM by gumby »
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline gumby

Re: Simulate user input
« Reply #2 on: March 10, 2013, 02:00:15 PM »
For simulating parser events:

Code: [Select]
           (send myEvent:
                 type(evKEYBOARD)
                 message("hello")    //  the 'said' string you want to pass in
                 modifiers(999)        // arbitrary modifier value, we'll check for this in user.sc
                 claimed(FALSE)
            )
            (User:handleEvent(myEvent))
            (send myEvent:dispose())

And then modify the user.sc code to look like this:
Code: [Select]
...

(if(canInput and not(send pEvent:claimed))
    (if( (== (send pEvent:message) echo) or (<= $20 (send pEvent:message)) and (<= (send pEvent:message) 255))
        (if( (self:getInput(pEvent)) and Parse(@inputStr pEvent))
            (send pEvent:type(evSAID))
            (self:said(pEvent))
        )
    )
    // add this section here
    (if( (== (send pEvent:modifiers) 999))
        StrCpy(@inputStr (send pEvent:message))
        (if(Parse(@inputStr pEvent))
            (send pEvent:type(evSAID))
            (self:said(pEvent))
        )
    )
)

...

There may be a better way to do this.  Basically, all I did was put the said string into the message property then set the modifiers to 999 (an arbitrary value).  Then in the user.sc & specifically look for the 999 modifier and shove the message text into the inputStr variable & do the parse.
In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.052 seconds with 21 queries.