WindowEvent() & EventMenuID() question

Everything else that doesn't fall into one of the other PB categories.
bernardfrancois
User
User
Posts: 47
Joined: Tue Sep 02, 2003 9:17 am
Location: Belgium
Contact:

WindowEvent() & EventMenuID() question

Post 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... ?
GreenGiant
Enthusiast
Enthusiast
Posts: 252
Joined: Fri Feb 20, 2004 5:43 pm

Post 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
User avatar
kenmo
Addict
Addict
Posts: 2033
Joined: Tue Dec 23, 2003 3:54 am

Post 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.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: WindowEvent() & EventMenuID() question

Post 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.
bernardfrancois
User
User
Posts: 47
Joined: Tue Sep 02, 2003 9:17 am
Location: Belgium
Contact:

Post 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
Post Reply