MaxGUI KEYDOWN events
BlitzMax Forums/BlitzMax Programming/MaxGUI KEYDOWN events
| ||
Can anyone point me to a good example of using KEYDOWN events in MaxGUI (since the KEYDOWN events used under the GRAPHICS command don't work under MaxGUI). I just need to get my arrow keys working again, and the docs are poor in the 'events' area. Thanks, -dak |
| ||
' createcanvas.bmx Strict Global GAME_WIDTH=320 Global GAME_HEIGHT=240 ' create a centered window with client size GAME_WIDTH,GAME_HEIGHT Local wx=(GadgetWidth(Desktop())-GAME_WIDTH)/2 Local wy=(GadgetHeight(Desktop())-GAME_HEIGHT)/2 Local window:TGadget=CreateWindow("My Canvas",wx,wy,GAME_WIDTH,GAME_HEIGHT,0,WINDOW_TITLEBAR|WINDOW_CLIENTCOORDS) ' create a canvas for our game Local canvas:TGadget=CreateCanvas(0,0,320,240,window) ' create an update timer CreateTimer 60 While WaitEvent() Select EventID() Case EVENT_TIMERTICK RedrawGadget canvas Case EVENT_GADGETPAINT Local g=CanvasGraphics(canvas) SetGraphics g SetOrigin 160,120 SetLineWidth 5 Cls Local t=MilliSecs() DrawLine 0,0,120*Cos(t),120*Sin(t) DrawLine 0,0,80*Cos(t/60),80*Sin(t/60) Flip Case EVENT_WINDOWCLOSE FreeGadget canvas End Case EVENT_KEYDOWN Select EventData() Case KEY_SPACE Print "Space down" End Select Case EVENT_APPTERMINATE End End Select Wend |
| ||
Thanks for the code sample, but it still doesn't work. The [Case EVENT_KEYDOWN] never executes. I added another print statement to check it. Case EVENT_KEYDOWN Print "keydown" Select EventData() Case KEY_SPACE Print "Space down" End Select |
| ||
Found it! you have to use [ActivateGadget canvas] to set the focus to the canvas gadget (or click on the canvas) in order for the EVENT_KEYDOWN to respond. |
| ||
That one took me a while to figure out too. I wouldn't mind canvases activating by default on creation myself... |
| ||
This *so* needs mentioning in the docs... |
| ||
from the CreateCanvas docs: When a Canvas is active using either the ActivateGadget command or clicking on the Canvas when the application is running, the following event's will also be sent from the Canvas: |
| ||
yeah, but the implications of that statement could be put a wee bit clearer, initialy it doesnt look like any gadget is active by default which is whats catching ppl out... |
| ||
I'm still lost. Why doesn't keydown and keyhit works. For me only the mouse doesn't work in debug mode. Yet I'll rather use a MaxGUI window for debug, or is it the same? So to make a quick replace for Keyhit/KeyDown Function KeyDown() If EventID() = EVENT_KEYDOWN 'EVENT_KEYHIT return EventData() Endif Endfunction Is that right? Or am I missing something? |
| ||
you could do that, I've written apps in c++ using the windows api and tabbing and key capture can be an absolute nightmare. I have every confidence that maxgui will evolve over time. Have you checked out the mouse over etc events? |
| ||
So the mouse is separate now? Before I used Keyhit(MOUSE_LEFT), So now I should use Event_MouseDown? |