EVENT_MOUSEMOVE / EventX() conflict with keyboard?
BlitzMax Forums/MaxGUI Module/EVENT_MOUSEMOVE / EventX() conflict with keyboard?
| ||
Hi, I'm having some trouble with the MOUSE_MOVE event, as it seems to be thrown even by the keyboard somewhat. Furthermore, it appears as when this event is thrown by the keyboard, EventX() and Event.X are not equal. Confusing! Here's a little code that demonstrate. Run this, and then, while moving the mouse, press a key. Here I get the debug message: DebugLog:Bug: Mouse Move event thrown by keyboard? event.X=404 eventx()=0 DebugLog:Bug: Mouse Move event thrown by keyboard? event.X=284 eventx()=0 DebugLog:Bug: Mouse Move event thrown by keyboard? event.X=286 eventx()=0 .... If fact, the event is not exactly thrown by the keypress: it's more like it's being registered and will get fired as soon as the mouse moves again. Code was tested only on Win32 XP. Strict Global MainWindow:TGadget = CreateWindow:TGadget("" , 40 , 40 , 500 , 300 , Null , WINDOW_TITLEBAR ) Global panel:TGadget = CreatePanel(0, 0, ClientWidth(MainWindow), ClientHeight(MainWindow), MainWindow, PANEL_ACTIVE | PANEL_BORDER) ActivateGadget(panel) AddHook EmitEventHook, MyHook Repeat WaitEvent() Local source:Object = EventSource() Local data:Int = EventData() If EventID() = EVENT_WINDOWCLOSE Then End Forever Function MyHook:Object(iId:Int,tData:Object,tContext:Object) Local Event:TEvent=TEvent(tData) If Event.ID = EVENT_MOUSEMOVE ' EventX() will be 0 when detecting a 'bad mouse move event' If EventX() = 0 Then Local tmp$ = "Bug: Mouse Move event thrown by keyboard? event.X=" + Event.X + " eventx()="+EventX() DebugLog tmp$ SetGadgetText(MainWindow, tmp$) End If EndIf Return tData End Function |
| ||
without checking the rest or testing: If EventX() = 0 Then -> Event.x :P edit: yep, that's cured it.. |
| ||
Thanks CS_TBL :) Short and sweet, it works. One must assume that EventX() and its family might not be updated correctly inside a hook. So bottom line: only use the 'event' in a hook and functions that could get called. |
| ||
The EventData(), EventX(), EventY(), EventID() etc. are globals, and are thus influenced from everywhere. When you're working with hooked stuff like this, then you'll be working with the .x, .y, .data, .id etc. fields from a TEvent object. |