Qbasicnews.com

Full Version: User32:GetAsyncKeyState aka Inkey$ dll for VB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Has anyone had any luck getting GetAsyncKeyState from user32 to function in fb? For some reason I am only getting nulls, even when I have a key down.

Code:
function keyb ( ) as string
dim Key as Long, Wait as Integer
For Key = 1 to 255
     if GetAsyncKeyState(Key) AND &H8000 <> 0 Then keyb = keyb + chr$(key)
Next key
Wait = Wait AND Len(keyb)
Do While Wait = 0
     Wait = 0
     For Key = 1 to 255
          If GetAsyncKeyState(Key) AND &H8000 <> 0 Then Wait = 1
     Next key
Loop
end function

Would GetAsyncKeyState(key) AND &H8000 be the same as
Vb's CBool(GetAsyncKeyState(key) AND &H8000)?
Written as source in VB it works great, but I was hoping to have FB compile it to a dll, and then call it from my FB/VB hybrid project. Any ideas??

Also in my experimentations on trying to get this to work in FB, I've also found that making a dll with Inkey$ or GetChar (as a substitute) causes VB to crash. Why would this be the case?
Try it with &H80 rather than &H8000.
Couple of things:

1) AND is used both for bitwise and logical operations, and as such it has less precedence than relational ops (than <> for example), so the tests must be changed to: if (GetAsyncKeyState(Key) AND &H8000) <> 0 -- the "()" are needed

2) keyb is a function and you are calling it recursively over and over, i dunno how it didn't crash:
keyb = keyb + chr$(key)
...
Wait = Wait AND Len(keyb)


I tested inkey$ with that dll example (inside mydll.bas) and it worked fine, but you can't mix VB strings with FB ones, they are not the same (VB6 uses OLE strings) -- if that's what you were doing.