Page 1 of 1

WindowEvent() & EventMenuID() question

Posted: Thu Jul 15, 2004 1:51 am
by bernardfrancois
Hi,

Have a look at the code below...
Syntax
Event = WindowEvent()

Description
Check if an event has occured on any of the opened windows.

Code: Select all

AddKeyboardShortcut(0,#PB_Shortcut_Return,5)

Code: Select all

WindowEvent()
If EventMenuID()=5 And shootball(closestball)=1 And dist<20
   MessageRequester("message","define the desired direction and press space")
   stage=2
EndIf
The last code snippet is placed in a loop.
The problem: When the return key is pressed and released, EventMenuID() will still return 5, instead of 0...
Its not really a bug, its in conformance with the description of the WindowEvent() command... but is it possible to reset the window event history?

Dunno if the explanation of my problem is clear... ?

Posted: Thu Jul 15, 2004 2:07 am
by GreenGiant
Here, you could try this code.

Code: Select all

ev=WindowEvent()
If ev=#PB_Event_Menu
  If EventMenuID()=5 And shootball(closestball)=1 And dist<20 
   MessageRequester("message","define the desired direction and press space") 
   stage=2 
  EndIf
EndIf
Or maybe even get rid of the menu shortcut and use this instead

Code: Select all

WindowEvent()
ev=EventType()
If ev=#PB_EventType_ReturnKey And shootball(closestball)=1 And dist<20 
 MessageRequester("message","define the desired direction and press space") 
 stage=2 
EndIf
But I havent had time to test either of these as its pretty late at night. I'll have another look in the morning

Posted: Thu Jul 15, 2004 2:15 am
by kenmo
Yeah, its because the eventmenuid() only updates when a shortcut (or menu item of course) is activated, so once you push it, the 5 will remain... but what you are doing wrong is not checking which event type has happened, so every single event will activate your code since the menuid is still 5...

So just do what GG did to test the event type.

Re: WindowEvent() & EventMenuID() question

Posted: Thu Jul 15, 2004 3:11 am
by PB
> is it possible to reset the window event history?

If you mean clear all pending events, then just do this:

Code: Select all

While WindowEvent() : Wend
This will clear all events in the queue.

Posted: Thu Jul 15, 2004 8:49 am
by bernardfrancois
thanks!

this didn't change anything... (but I dont understand why, coz normally it should work.. :?: )

Code: Select all

        WindowEvent()
        ev=EventType()
        If EventMenuID()=5 And shootball(closestball)=1 And dist<20       
          MessageRequester("message","define the desired direction and press space")
          stage=2
        EndIf
        
        While WindowEvent() : Wend
and this code didn't do anything when pressing return...

Code: Select all

        WindowEvent()
        If  EventType()=#PB_EventType_ReturnKey And shootball(closestball)=1 And dist<20        
          MessageRequester("message","define the desired direction and press space")
          stage=2
        EndIf
but this one did the job :D :

Code: Select all

        If WindowEvent()=#PB_Event_Menu    
          If  EventMenuID()=5 And shootball(closestball)=1 And dist<20                  
            chosenball=closestball
            MessageRequester("message","define the desired direction and press space")
            stage=2
          EndIf
        EndIf