Force Windows focus to Blitz?

Blitz3D Forums/Blitz3D Programming/Force Windows focus to Blitz?

Shifty Geezer(Posted 2009) [#1]
Is there any way I can force Window's input focus to Blitz? I'm using the old Accode Flash plugin (http://www.blitzbasic.com/Community/posts.php?topic=51053) which works nicely, but clicking in the Flash window steals focus and I can no longer input via keyboard or mouse in the Blitz portion of the screen! this makes interacting with the Flash aspect very limited. :(


Warner(Posted 2009) [#2]
Instead of using the standard keyboard commands, you could try GetASyncKeyState. It will tell you which keys are down, regardless if the window has focus or not.


jfk EO-11110(Posted 2009) [#3]
Using WindowSetPos (I guess that's the one), an API command that can be declared in a Blitz userlib, will not only focus the keyboard input, but the entire window onscreen. Not sure if this is what you want.


Shifty Geezer(Posted 2009) [#4]
Thanks jfk. That could do it, if I just move the window to its current position. Can you offer any pointers to linking Windows APIs, something i am utterly clueless about, and where I can look up these APIs?! Then I could dig around for other useful thingums. Cheers.


chi(Posted 2009) [#5]
http://msdn.microsoft.com/en-us/library/aa383749%28VS.85%29.aspx
or
http://allapi.mentalis.org/agnet/apiguide.shtml


Warner(Posted 2009) [#6]
Still, GetASyncKeyState would be better, since it can be a bit disturbing for users if a window forces itself into focus.


jfk EO-11110(Posted 2009) [#7]
Warner may be right in this case. It's always good to have the Windows API help file onboard, you may dl it eg. from here:

http://www.carabez.com/downloads.html

At the bottom, win32api.zip. as well as the winapi constants that you'llneed too. The seven seals sotosay.


Shifty Geezer(Posted 2009) [#8]
Hmm. I'll have a look at GetAsyncKeyState. At the moment mouse doesn't work in Blitz when it's lost focus, and clicking in the window doesn't restore it. But then if I'm stealing focus constantly, that'll mess up multitasking. Then again, you shouldn't be multitasking with my app anyhow ;)

Thanks for all suggestions.


Warner(Posted 2009) [#9]
There is also an api command to read mouse coords: getCursorPos
http://www.blitzbasic.com/Community/posts.php?topic=50372


Shifty Geezer(Posted 2009) [#10]
Thanks for the info. I can read keys perfectly now. However, this throws up the problem of ASCII interpretation! If I determine through GetAsyncKeyState() that certain kesy are pressed, that'll correspond to different characters on different keyboards. eg. I think 'shift+2' is " on the UK keyboard but @ on the US keyboard.

Windows handles these conversions through it's keyboard structures, but I can't see how to access them. TranslateMessage etc. seem the right functions in principle but they talk of posting to a message queue. I cannot see any way to properly map individual key presses from GetAsnycKeyState() to the right, localised ASCII value.

Is there perhaps a layout structure that holds a map of keystates and characters that I could reference? I can't find such a think in the help file jfk EO-11110 so helpfully linked above, but it can get a bit spaghetti digging through there!


Warner(Posted 2009) [#11]
Maybe you could create a message structure, then use TranslateMessage, followed by GetKey() to read the ascii value?
Maybe this archive entry can help:
http://www.blitzmax.com/codearcs/codearcs.php?code=2093


Shifty Geezer(Posted 2009) [#12]
That looks very promising, but I'm not getting anything from it. :( I've copied out the structures and eventHandler() function. I call the function and test for message responses with prints and stops at mouse clicks, key presses etc., but get nowt. Every frame I print the contents of w_message and it's blank. I've set the app hWnd in the w_message.

Even just trying this:

i = api_PeekMessage(w_message, SystemProperty("appHWND"),0,256,0)

i never returns a non-zero value. Surely it should be recording key presses and mouse clicks?


Warner(Posted 2009) [#13]
I was thinking along the lines of this:
1. Create a fake event, using the Type structure in the above archive entry.
2. Fill the event with the keycode you want to convert
3. Call TranslateMessage with this event
4. See if GetKey() returns anything


Guy Fawkes(Posted 2009) [#14]
Warner, check ur mail