Does 'keydown' work in B+ alongside Waitevent()?

BlitzPlus Forums/BlitzPlus Programming/Does 'keydown' work in B+ alongside Waitevent()?

Matty(Posted 2005) [#1]
I'll post some code later today (when I'm at my dev PC) but I have been having trouble detecting keyboard input using keyhit/keydown while in a loop "while waitevent()...stuff goes here... wend". The window I have has a canvas and some buttons. What I am trying to do is move the cursor over the canvas with the mouse and use the keyboard at the same time.

from memory the code, is something like:

timer=createtimer(60)
while waitevent()

select eventid()

;a few events are checked for here like $401, $803 
case $803
end ;for example

case $4001 ;the timer event, although this problem occurs even if I have the keydown statement outside of the select statement.
if keydown(203) then notify("Yes I did push the left cursor key so why doesn't this message appear")
flushevents $4001

end select

wend




CS_TBL(Posted 2005) [#2]
Can't you use GetASyncKeyState?


Matty(Posted 2005) [#3]
I can't see that command in the docs. It's not in the downloadable documentation or the online one - what does it do?


CS_TBL(Posted 2005) [#4]
It's in some standard DLL (dunno which one), it's basically an advanced keyboard reader.. I don't use anything else anymore, like keydown, hotkeyevent etc. etc.
- it keeps the focus (yay!)
- it also works when you switch to another app (like mIRC .. highly inconvenient as you can imagine, but ofcourse you can code that the keyboardroutines don't work when you switch app)
- it features key-repeat

I made (and published) some nice standard routines a few months ago.. I'll try to dig them up.

'ere: http://www.blitzbasic.co.nz/Community/posts.php?topic=44780


VIP3R(Posted 2005) [#5]
You don't need to use GetASyncKeyState for that, the window is still in focus is it not?

You should be detecting it like this...
If EventID()=$101 and EventData()=203 Then Notify ("Left Key Pressed")

or using Select/Case...
Select EventID()
Case $101
If EventData()=203 Then Notify ("Left Key Pressed")
End Select

GetASyncKeyState is a function in the User32.dll lib btw.


Nicstt(Posted 2005) [#6]
keyhit stops working once most gadgets have been clicked, the exception ive noticed so far is slider controls


VIP3R(Posted 2005) [#7]
You shouldn't be using KeyHit or KeyDown with WaitEvent() or windowed apps, they are meant for full screen use.

Why do you think there are specific events allocated for detecting keys?

KeyDown = EventID() $101
KeyUp = EventID() $102
KeyStroke = EventID() $103


Matty(Posted 2005) [#8]
How then do you detect two or more events that happens simultaneously though? If I have multiple keys being pressed then normally (in blitzbasic and blitz3d) I can simply check various scancodes with keydown. There doesn't seem to be a 'queue' of events that I can iterate through to do this with events $101/$102/$103. Same goes for both mouse and keyboard input at same time.


WolRon(Posted 2005) [#9]
There doesn't seem to be a 'queue' of events that I can iterate through

Yes there is. Try PeekEvent.