I need to set up a Keydown() function to work either with a window, or without anything at all. I am not using the Blitz Graphics() command.
KeyDown() without Graphics()
BlitzMax Forums/BlitzMax Programming/KeyDown() without Graphics() You need to use events instead.
Those would be fine as well, but they don't work without a canvas.
You can use a panel with PANEL_ACTIVE set, then you'll get events.
Sweet!
pah, still sux.
1: You need to click on the panel before it creates key-events
2: still no key-repeat (event id 515), so cursor-repeat, as well as other keys (F-keys etc.). So no real use for keyboard-based editing yet.
In B+ you didn't need any panel or canvas.. keys were just there..
1: You need to click on the panel before it creates key-events
2: still no key-repeat (event id 515), so cursor-repeat, as well as other keys (F-keys etc.). So no real use for keyboard-based editing yet.
In B+ you didn't need any panel or canvas.. keys were just there..
Use ActivateGadget() to activate the panel.
It still doesnt' fix issue 2.
I'd say it's a feature-lack for the moment.. I rather have no requiring panels or canvases for keypresses, just like B+..
I'd say it's a feature-lack for the moment.. I rather have no requiring panels or canvases for keypresses, just like B+..
The key is pressed until you get an EVENT_KEYUP
IF you use WinXp and have MinGW properly installed you could do a hack to the Win32Gui Module.
For details : Take a look at http://www.blitzbasic.com/Community/posts.php?topic=55069#614872
If change it to : setEventMask( BBEVENT_MOUSEMASK|BBEVENT_KEYMASK,this ) then
you have to call EnablePolledInput before your main loop and the KeyDown and KeyHit also MouseX and Y and MouseHit commands will work.
PS: Works for nearly every Gadget but not for the DesktopGadget
For details : Take a look at http://www.blitzbasic.com/Community/posts.php?topic=55069#614872
If change it to : setEventMask( BBEVENT_MOUSEMASK|BBEVENT_KEYMASK,this ) then
you have to call EnablePolledInput before your main loop and the KeyDown and KeyHit also MouseX and Y and MouseHit commands will work.
PS: Works for nearly every Gadget but not for the DesktopGadget
btw, I'm not looking for keyrepeat as used in games (no delay).
But more like:
[press][delay][repeat][repeat][repeat][repeat][repeat][repeat][repeat][repeat][repeat][keyup]
The delay is important.
see this B+ code:
Things should work/feel exactly like this.. I dunno about all that polled stuff, I basically want to do events-only orso.. all my keyboard routines ar meant for apps, not games.
At the moment it isn't possible with bmax-events natively, unless someone proves me wrong. :P
(oh, and I don't have xp/mingw)
ps. note that I only used a canvas here to visualise the effect, a canvas or panel is not required.
But more like:
[press][delay][repeat][repeat][repeat][repeat][repeat][repeat][repeat][repeat][repeat][keyup]
The delay is important.
see this B+ code:
window=CreateWindow("._.",0,0,640,480) canvas=CreateCanvas(0,0,640,480,window) Repeat WaitEvent() If EventID()=$803 End SetBuffer CanvasBuffer(canvas) Cls Text 2,2,EventID()+" "+EventData() If EventID()=259 ; keyrepeat If EventData()=63232 ; up y=y-8 EndIf If EventData()=63233 ; dn y=y+8 EndIf If EventData()=63276 ; pgup y=y-32 EndIf If EventData()=63277 ; pgdn y=y+32 EndIf If EventData()=63273 ; home y=0 EndIf If EventData()=63275 ; end y=400 EndIf If EventData()=63234 ; l x=x-8 EndIf If EventData()=63235 ; r x=x+8 EndIf If EventData()=63236 ; F1 x=Rnd(600) y=Rnd(400) EndIf EndIf Rect x,y,8,8,1 FlipCanvas canvas Forever
Things should work/feel exactly like this.. I dunno about all that polled stuff, I basically want to do events-only orso.. all my keyboard routines ar meant for apps, not games.
At the moment it isn't possible with bmax-events natively, unless someone proves me wrong. :P
(oh, and I don't have xp/mingw)
ps. note that I only used a canvas here to visualise the effect, a canvas or panel is not required.
If you want to handle it this way, you have to hack the Win32Gui Source as mentioned above and then catch the events like in B+.
hm.. too complex for me..
I ready-made solution (meaning: EVENT_KEYCHAR is created by a window) is appreciated tho. ^_^
I ready-made solution (meaning: EVENT_KEYCHAR is created by a window) is appreciated tho. ^_^
Dude, just use EnablePolledInput().
For Keydown() events, I usually just enter a loop and don't exit until the KeyUp() event is encountered.
For Keydown() events, I usually just enter a loop and don't exit until the KeyUp() event is encountered.
Then convert that B+ source put there above to bmax please, as small as possible and with the natural delay. :P
lol@... liberal use of the word, nevermind ;)
!!!!
Dude, just use EnablePolledInput().
For Keydown() events, I usually just enter a loop and don't exit until the KeyUp() event is encountered.
Please give an example! I'm going crazy...
I've tried something like this
I used PollEvent() but nothing to do..
but nothing to do: and I dont' want a WaitEvent() call.
Dude, just use EnablePolledInput().
For Keydown() events, I usually just enter a loop and don't exit until the KeyUp() event is encountered.
Please give an example! I'm going crazy...
I've tried something like this
enablepolledinput() Repeat Print "..." If EventID()=EVENT_KEYUP Print "key pressed";go_exit=1 Until go_exit=1 End
I used PollEvent() but nothing to do..
but nothing to do: and I dont' want a WaitEvent() call.
Why don't you want a WaitEvent?? What's more glorious and luxury than an event system??
because WAITEVENT() halts program execution until an event is available: this mean that other processes are stopped...
What other processes? game-updates/AI? Stick them to an EVENT_TIMERTICK :P You *can* create games with events you know..
enablepolledinput()
Repeat
Print "..."
If KeyDown(KEY_UP) end
forever
Repeat
Print "..."
If KeyDown(KEY_UP) end
forever
Strict Local win_main:tgadget=CreateWindow("Test",50,50,300,200,Null,WINDOW_TITLEBAR) enablepolledinput() While True WaitEvent Print CurrentEvent.ToString() Select EventID() Case EVENT_KEYDOWN Print "key pressed" Case EVENT_WINDOWCLOSE End End Select Wend
This program emits or not a KeyDown Event? On my computer I CAN NOT catch a keyboard event...
:(
Please gimme an hint, I lost a week of life for this...
@Halo: thanks for the example but I didn't work...
i think it only lets you use EVENT_KEYDOWN when a canvas is active.
enabledpolledinput() just lets you use keydown() keyhit() and such like.
enabledpolledinput() just lets you use keydown() keyhit() and such like.
Strict Local win_main:tgadget=CreateWindow("Test",50,50,300,200,Null,WINDOW_TITLEBAR) Local can_main:tgadget=CreateCanvas(0,0,ClientWidth(win_main),ClientHeight(win_main), win_main) ActivateGadget can_main enablepolledinput() While True WaitEvent Print CurrentEvent.ToString() Select EventID() Case EVENT_WINDOWCLOSE End End Select If KeyHit(KEY_ESCAPE) Then End Wend
So only with a canvas active I can intercept key event...
Maybe I've misinterpreted the command 'enablepolledinput()'
Thanks
Maybe I've misinterpreted the command 'enablepolledinput()'
Thanks