|
Post by Grexie on Sept 8, 2022 13:16:04 GMT -5
Hi, how can I do a keyboard inquiry in the main window? When I use INKEY$ in the main window, the app crashes. I read that INKEY$ only works in graphics mode. Is that right? Is there another way to program a keyboard inquiry in the main window?
|
|
|
Post by tsh73 on Sept 8, 2022 14:12:25 GMT -5
Well, the power of LB is ability to call Windows API I cobbled a demo of GetAsyncKeyState from pieces by other people It move thing in a mainwin with cursor keys or WASD but 0) it looks OK for arrow keys but 1) letters pressed (WASD) get printed to mainwin as well 2) it keeps working even if you switch focus to another window Probably one should check if active window is our's
Someone more versed in API could probably fix that (or suggest another solution)
x=30:y=10
timer 50, [tick]
wait
[tick] scan dx=0:dy=0 if GetAsyncKeyState(asc("W")) or GetAsyncKeyState(_VK_UP) then dy = -1 if GetAsyncKeyState(asc("S")) or GetAsyncKeyState(_VK_DOWN) then dy = 1 if GetAsyncKeyState(asc("A")) or GetAsyncKeyState(_VK_LEFT) then dx = -1 if GetAsyncKeyState(asc("D")) or GetAsyncKeyState(_VK_RIGHT) then dx = 1 'print dx, dy locate x, y: print"<#>" if dx<>0 or dy <>0 then locate x, y: print" " x=x+dx:y=y+dy locate x, y: print"<#>" end if wait
function GetAsyncKeyState(key) calldll #user32, "GetAsyncKeyState",key as long,GetAsyncKeyState as long if GetAsyncKeyState<>0 then GetAsyncKeyState=1 end function
|
|
|
Post by Walt Decker on Sept 8, 2022 18:52:01 GMT -5
NOMAINWIN supresses LB's default main window. OPEN "MAIN WIN" FOR WINDOW AS #MAIN creates a MSWIN form window. To which are you refering?
One should always mask out the return value from GetAsynKeyState to obtain the correct key combination. What if VK_RETURN and VK_CONTROL are pressed at the same time? Just querying the return value will not give you the correct result.
|
|
|
Post by Rod on Sept 9, 2022 1:34:21 GMT -5
A good tip would be “don’t even try”. You can stop and obtain input in the mainwin but you cannot loop and check keys without some issues as tsh73 and Walt discuss.
The mainwin is essentially a coding and debugging window. It is meant to be switched off once your application is running well. Your application will use the GUI controls Liberty provides.
Many people do use the mainwin to create applications. It is perfectly possible to do this so long as you are aware of the in key and input and color use restrictions.
Best open the example programs that ship with Liberty to get a feel for mainwin and GUI differences.
|
|