PDA

View Full Version : canvas getwindowkey qt



largo_winch
08-10-2013, 11:02
how I can get infos or an thinbasic example about canvas/"getwindowkeystate" (for example: (%VK_L, %VK_B) in GUI modus ?

or something like


If GetAsyncKeyState(%VK_ESCAPE) Then
Dialog End hDlg

End If



but that's not working in canvas mode for one-letter-key strokes.

largo_winch
09-10-2013, 20:52
something I have built this afternoon:


' Basic Template for custom dialog
' Start Date 10-09-2013
' Created by

Uses "UI"


' -- ID numbers of controls
Begin ControlID
%bClose
%myLabel
End ControlID


Begin Const
%MAIN_WIDTH = 420
%MAIN_HEIGHT = 340
End Const


' -- Create dialog here
Function TBMain()
Local hDlg,counts As Long
Local strx As String


Dialog New Pixels, 0, "GetKeyState_test",-1,-1, %MAIN_WIDTH, %MAIN_HEIGHT, _
%WS_POPUP Or %WS_VISIBLE Or %WS_CAPTION Or %WS_SYSMENU Or %WS_MINIMIZEBOX To hDlg

' -- Place controls here
Control Add Button, hDlg, %bClose, "Click to close", %MAIN_WIDTH-105, %MAIN_HEIGHT-30, 100, 25, Call cbCloseButton
Control Add Label, hDlg, %myLabel, "", 5, 40, 202, 268, _
%WS_CHILD Or %WS_VISIBLE Or %WS_BORDER Or %SS_LEFT Or %SS_SUNKEN, _
%WS_EX_CLIENTEDGE Or %WS_EX_LEFT Or %WS_EX_LTRREADING


'Dialog Show Modal hDlg, Call cbDialog
Dialog Show Modeless hDlg, Call cbDialog
Do
If GetAsyncKeyState(Asc("A")) And &H80 > 0 Then strx = strx + "'A' is pressed" + $CRLF

If GetAsyncKeyState(Asc("B")) And &H80 > 0 Then strx = strx + "'B' is pressed" + $CRLF

Control Set Text hDlg, %myLabel, strx
Dialog DoEvents To counts
Loop Until counts = 0

End Function


' -- Callback for dialog
CallBack Function cbDialog()

' -- Test for messages
Select Case CBMSG


Case %WM_INITDIALOG
' -- Put code to be executed after dialog creation here


Case %WM_COMMAND
' -- You can handle controls here


'SELECT CASE CBCTL
'
' CASE ...
' IF CBCTLMSG = ... THEN
'
' END IF
'
'END SELECT




Case %WM_CLOSE
' -- Put code to be executed before dialog end here
'Case %WM_KEYDOWN
'If GetAsyncKeyState(Asc("A")) And &H80 > 0 Then strx = strx + "'A' is pressed" + $CRLF
End Select


End Function

' -- Callback for close button
CallBack Function cbCloseButton()


If CBMSG = %WM_COMMAND Then
If CBCTLMSG = %BN_CLICKED Then
' -- Closes the dialog
Dialog End CBHNDL
End If
End If


End Function



this example works for some keys, not bad. now my next step is to built in this "GetAsyncKeyState" in callback part.

interesting that this example only runs with "modeless" and a loop.

bye, largo