Keyboard input in MaxGUI
BlitzMax Forums/BlitzMax Programming/Keyboard input in MaxGUI
| ||
I cannot get keyboard input to work in MaxGUI. Here's my code:WaitEvent() myEvent=EventID() if myEvent=EVENT_KEYDOWN then keyPressed=EventData() But keyPressed is always 0. I did a couple more tests, and I can't even get it to generate a single EVENT_KEYDOWN event. |
| ||
Is KeyPressed alway 0, or is it always NULL (ie if you run it in strict, does it fail) What waitevent is doing, is taking all the events one at a time, and so there is a possibility you are only taking the first event, then if its not a keydown event not looping back. ie It needs to be in a loop. Heres mine While WaitEvent() Select EventID() Case EVENT_GADGETPAINT SetGraphics (CanvasGraphics(NameOfCanvas)) Cls Case EVENT_WINDOWCLOSE FreeGadget NameOfCanvas FreeGadget NameOfWindow End Case EVENT_KEYDOWN Select EventData() Case KEY_SPACE PostEvent( CreateEvent:TEvent (EVENT_WINDOWCLOSE) ) End Select Case EVENT_APPTERMINATE End End Select WendAll this would do is close the application when space is pressed. As you can see the main thing is that its in a loop (While Wend) The bit for Key presses (Well KeyDown), has another select on EventData. You dont need to do this, but you definatly need to loop through the events until you find one that is a keyDown(or whatever) |
| ||
Tried looping through pollevent() until it returns null and I still can't get anything useful. |
| ||
Do you actually have anything that can fire key events like a Canvas or panel? Textarea, textfield for example don't fire keyboard events |
| ||
That would be my problem then. Anyone know a link to some sample code? |
| ||
Try this codeSuperStrict Local MyWindow:TGadget=CreateWindow("Canvas Example", 200,200,320,240) Local MyCanvas:TGadget=CreateCanvas(10,10,290,140,MyWindow) ActivateGadget MyCanvas Local x:Int=100 Local y:Int=10 Repeat WaitEvent() Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_KEYDOWN Select EventData() Case KEY_LEFT x:- 3 Case KEY_RIGHT x:+ 3 EndSelect RedrawGadget(MyCanvas) Case EVENT_GADGETPAINT SetGraphics CanvasGraphics (MyCanvas) Cls DrawRect x,y,40,40 Flip End Select Forever You may want to go thru this two tutorials http://www.2dgamecreators.com/maxgui/T12-Canvas.html http://www.2dgamecreators.com/maxgui/Mouseevents.html They are for mouse events but the principles are similar |