Announcement

Collapse
No announcement yet.

input

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • input

    I just wanted to confirm, since version 9 does not show inkey$

    to get, trap, use key strokes in a program you must use winapi?

    thanks

  • #2
    In a GUI program, you process notification messages .. and you'll get a notification message for every keystroke the user types.

    If the user is entering text in an edit (DDT 'TEXTBOX') control, every keystroke will result in a WM_COMMAND/EN_CHANGE notification message to your Window/Dialog procedure (your 'CALLBACK FUNCTION' if using DDT).

    There are some other ways to receive notifications for SPECIFIC keys (eg, you want to trap all "F1" so you can show "Help"), but for suggestions you might wish to describe what you want to do in a bit more detail.

    A primary user-interface difference between Windows' GUI programs and either your MS-DOS programs or a Windows/Console program is, in MS-DOS/Console programs, you ask if the user has pressed a key (INKEY$) ; in Windows/GUI programs, Windows tells you the user has typed something, without you asking (notification messages).

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      input

      i am making a graphic window
      in a do loop for users
      if they press ESC i want everything to exit and close
      i will test inkey$ again in the loop to see where i may be doing something wrong
      i perfer not to use win api 's

      Comment


      • #4
        PBWin 9 has a GRAPHIC INKEY$ statement for reading keyboard characters. There is also GRAPHIC INPUT, GRAPHIC WAITKEY$, etc in PBWin 9. See http://www.powerbasic.com/support/he..._functions.htm for a complete list of all the graphical functions in PBWin 9.
        Sincerely,

        Steve Rossell
        PowerBASIC Staff

        Comment


        • #5
          ty

          thanks for the info

          Comment


          • #6
            GRAPHIC INKEY$ works wrong?

            Originally posted by Steve Rossell View Post
            PBWin 9 has a GRAPHIC INKEY$ statement for reading keyboard characters.
            I tested "GRAPHIC INKEY$" operator for PBWin 9.01, in modeless dialog. As it said in the Keyword Reference, "A string length of two means that an extended key was pressed. In this case, the first character in the string has an ASCII value of zero, and the second is the extended keyboard code."
            So, to my sorry, my program can't see input strings 2's length! It well catch normal characters (english and russian), two ASCII codes (CR and BACKSPACE), but can't see Esc, Ctrl-F5 and so on. Attempt to input the F10 key stops running program until press F10 for the next time.
            What's wrong?
            This is my first posting here, sorry if I'd override some rools.

            Comment


            • #7
              Alex:

              Test your entered characters with the LEN(CH$) function to see whether is a single or double. If double read the second one with MID$(CH$,2,1).

              Regards,

              Comment


              • #8
                Sample code for Graphic Inkey$..
                Code:
                #DIM ALL
                #INCLUDE "WIN32API.INC"
                 
                FUNCTION PBMAIN()
                 LOCAL hGWnd AS DWORD
                 LOCAL sKey, sTemp AS STRING
                 LOCAL Clk, x, y AS LONG
                 
                  GRAPHIC WINDOW "Graphic Window", 50, 50, 300, 300 TO hGWnd
                  GRAPHIC ATTACH hGWnd, 0
                 
                  WHILE ISWIN(hGWnd)
                    GRAPHIC INKEY$ TO sKey                         ' Capture arrow keys etc
                    SELECT CASE LEN(sKey)
                      CASE 0                                        ' No keys pressed
                        DIALOG DOEVENTS
                      CASE 1                                        ' ASCII Key pressed
                        DIALOG SET TEXT hGWnd, " " + sKey + Str$(ASC(sKey))
                        IF ASC(sKey) >1 AND ASC(sKey) <31 THEN DIALOG SET TEXT hGWnd, " " + "Control Code" + STR$(ASC(sKey))
                        IF sKey = $ESC THEN                         ' Quit on Escape
                          DIALOG SET TEXT hGWnd, "Escape key pressed - Bye!" : SLEEP 2000
                          EXIT LOOP
                        END IF
                      CASE 2                                        ' Extended key pressed - * NB not number pad *
                        SELECT CASE ASC(RIGHT$(sKey,1))
                          CASE 69 : sTemp = "NumLock"
                          CASE 71 : sTemp = "Home"                  ' *
                          CASE 72 : sTemp = "Up Arrow"
                          CASE 73 : sTemp = "Page up"               ' *
                          CASE 75 : sTemp = "Left arrow"
                          CASE 77 : sTemp = "Right arrow"
                          CASE 79 : sTemp = "End"                   ' *
                          CASE 80 : sTemp = "Down arrow"
                          CASE 81 : sTemp = "Page down"             ' *
                          CASE 82 : sTemp = "Insert"
                          CASE 83 : sTemp = "Delete"
                          CASE ELSE : sTemp = "Etc.."
                        END SELECT
                        DIALOG SET TEXT hGWnd, " " + STR$(ASC(RIGHT$(sKey,1))) + "  " + sTemp : sTemp = ""
                    END SELECT
                    ' As we're looping anyway let's test for clicks..
                    GRAPHIC WINDOW CLICK hGWnd TO Clk&, x&, y&
                    IF Clk = 2 THEN
                        WinBeep 800,1   ' double click
                    ELSEIF Clk = 1 THEN
                      GRAPHIC SET POS (0, 0) : GRAPHIC PRINT "                          " ' clear old pos info
                      GRAPHIC SET POS (0, 0)   
                      GRAPHIC PRINT " x:"+STR$(x)+", y:"+STR$(y)                    ' click position in GfxWindow
                    END IF
                  WEND
                 
                END FUNCTION
                '------------------/
                Last edited by Dave Biggs; 9 Jun 2009, 11:42 AM. Reason: Reset sTemp
                Rgds, Dave

                Comment


                • #9
                  2Manuel: Of course, I check length of getting symbol.
                  2Dave Biggs: Yeap, your program is working /although on the beginning of CASE 2 it's better to clear sTemp :laugh: /
                  But it is very very simple.
                  What do you think about my program? Why it didn't work?

                  Code:
                  '================= tstgrph.bas PBWin 9.01 by Alex Trenty
                  #DIM ALL
                  #COMPILE EXE
                  #INCLUDE  "WIN32API.INC"
                  GLOBAL AWin     AS DWORD ' Graphic Window Handle
                  $AppTitle = "Test graphics especially"
                  $pFont1          = "Lucida Console"
                  $pFont2          = "Arial"
                  $pFont3          = "Courier New"
                  $pFont4          = "Arial Black"
                  $pFont5          = "Times new Roman"
                  GLOBAL fZagl    AS LONG
                  GLOBAL fTxt1    AS LONG
                  GLOBAL fZagB    AS LONG
                  GLOBAL fTime    AS LONG
                  %ID_OK  =   100
                  %ID_S1  =   101
                  %ID_S2  =   102
                  %ID_S3  =   103
                  %ID_S4  =   104
                  %ID_S5  =   105
                  %ID_S6  =   106
                  %ID_GA  =   200
                  %wW     = 560&
                  %wH     = 540&
                  %aR=10: %aD= 80: %aW=460: %aH=300 ' Graphic Window
                  GLOBAL hDlg  AS LONG
                  GLOBAL hWnd  AS LONG
                  GLOBAL fDlgEnd AS LONG
                  GLOBAL hThread AS LONG
                  GLOBAL fThrClose AS LONG
                  GLOBAL Result AS LONG
                  GLOBAL hTimer    AS LONG   ' Handle íà åæåñåêóíäíûé òàéìåð
                  GLOBAL fTimer    AS LONG   ' Timer Flag
                  GLOBAL lTimer    AS LONG   ' Countdown from 2 to 0
                  GLOBAL wTimer    AS LONG   ' Flag=1 every 0,5s
                  GLOBAL cDat1        AS STRING*10 ' as is
                  GLOBAL cDat2        AS STRING*8  ' dd/mm-yy
                  GLOBAL cDat3        AS STRING*19 ' dd/mm-yy = cc:mm:ss
                  GLOBAL x,y       AS SINGLE: GLOBAL fUnd AS LONG
                  GLOBAL sI        AS STRING
                  GLOBAL fI        AS LONG
                  GLOBAL xM1, yM1, xM2, yM2 AS LONG
                  GLOBAL s5 AS STRING
                  GLOBAL hWin  AS LONG
                  GLOBAL xG,yG AS LONG
                  GLOBAL hGraphic AS DWORD
                   
                  FUNCTION Timer_Event () AS LONG ' -------------- Issued every 0,5s
                      fTimer=%TRUE: FUNCTION=0
                  END FUNCTION
                  SUB CurTime()
                      cDat1=DATE$: cDat2=MID$(cDat1,4,2)+"/"+MID$(cDat1,1,2)+"-"+MID$(cDat1,9,2)
                      cDat3=cDat2+" - "+TIME$
                  END SUB
                   
                  '====================================================================
                  CALLBACK FUNCTION D_CB() AS LONG
                  '--------------------------------------------------------------------
                    LOCAL pT AS POINTAPI
                    SELECT CASE CB.MSG
                    CASE %WM_DESTROY
                       fDlgEnd=%TRUE
                    CASE %WM_PARENTNOTIFY ' Detect L/R Click to Interest Place
                       pT.x = LO(WORD,CB.LPARAM)
                       pT.y = HI(WORD,CB.LPARAM)
                       MapWindowPoints CB.HNDL, 0, pT, 1
                       IF LO(WORD,CB.WPARAM) = %WM_LButtonDown THEN
                          s5=s5+"L": CONTROL SET TEXT hDlg,%ID_S5,s5
                       ELSEIF LO(WORD,CB.WPARAM) = %WM_RButtonDown THEN
                          s5=s5+"R": CONTROL SET TEXT hDlg,%ID_S5,s5
                       END IF
                    CASE %WM_LButtonUp
                          s5=s5+"l": CONTROL SET TEXT hDlg,%ID_S5,s5
                    CASE %WM_RButtonUp
                          s5=s5+"r": CONTROL SET TEXT hDlg,%ID_S5,s5
                    CASE %WM_COMMAND
                       IF CB.CTLMSG=%BN_CLICKED AND CB.CTL=%ID_OK THEN fDlgEnd=%TRUE: EXIT SELECT
                       IF CB.CTL=%ID_GA THEN
                          GetCursorPos(pT): ScreenToClient(AWin,pT)
                          CONTROL SET TEXT hDlg,%ID_S3,"!CB.MSG="+FORMAT$(CB.MSG,"0000")+ _
                           ", CB.CTLMSG="+STR$(CB.CTLMSG)+", x="+STR$(pT.x)+ _
                           ", y="+STR$(pT.y): EXIT SELECT
                       END IF
                    END SELECT
                  END FUNCTION
                  '============= Thread ====================================
                  FUNCTION eThread (BYVAL hDlg AS LONG) AS LONG
                   LOCAL s AS STRING
                   WHILE ISFALSE fThrClose
                    ERRCLEAR
                    IF wTimer>0 THEN
                        wTimer=0: DECR lTimer
                        CurTime: CONTROL SET TEXT hDlg,%ID_S4,CDat3 ' Date,Time every 0,5s
                        IF lTimer<0 THEN CONTROL SET TEXT hDlg,%ID_S6,"": lTimer=2
                        fUnd=1-fUnd: IF fUnd=0 THEN s=" " ELSE s="_"
                        GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC SET POS (x,y)
                        GRAPHIC FONT $pFont3,10,0: GRAPHIC COLOR %BLACK
                        GRAPHIC PRINT s; '<========================== Underscore
                    END IF
                    IF fI=2 THEN  ' Output catched symbol
                        IF LEN(sI)=1 AND ASC(sI,1)>31 THEN ' <-----------------Normal Chr
                            GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC SET POS (x,y)
                            GRAPHIC SET FONT fTxt1: GRAPHIC COLOR %BLUE
                            GRAPHIC PRINT sI;: GRAPHIC GET POS TO x,y
                        ELSEIF LEN(sI)=1 THEN '   <------------------ Control Chr [xx]
                            GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC SET POS (x,y)
                            GRAPHIC SET FONT fTxt1: GRAPHIC COLOR %RED
                            GRAPHIC PRINT "["+LTRIM$(STR$(ASC(sI,1)))+"]";
                            IF ASC(sI,1)=13 THEN ' CR
                                GRAPHIC PRINT: GRAPHIC GET POS TO x,y: GRAPHIC SET POS (12,y)
                                GRAPHIC COLOR %BLACK: GRAPHIC SET FONT fTxt1: GRAPHIC PRINT ">";
                            END IF
                            GRAPHIC GET POS TO x,y
                        ELSE '    <----------------------- Special Characters - WHERE ARE ??
                            GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC SET POS (x,y)
                            GRAPHIC SET FONT fTxt1: GRAPHIC COLOR %YELLOW
                            GRAPHIC PRINT "{"+LTRIM$(STR$(ASC(sI,2)))+"}";
                            GRAPHIC GET POS TO x,y
                        END IF: fI=0
                    END IF
                    SLEEP 20
                   WEND: FUNCTION = %TRUE
                  END FUNCTION
                   
                  ' ==================================
                  FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInst AS DWORD, _
                     BYVAL pCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                  #REGISTER NONE
                     LOCAL v,pN,t,sT AS STRING, i AS DWORD, dW,dH,tR,tD AS LONG
                   DESKTOP GET CLIENT TO dW, dH
                   tR=(dW-%wW)/2: tD=(dH-%wH)/2
                   FONT NEW $pFont2,12,1,204,0 TO fZagl
                   FONT NEW $pFont3,10,0,204,0 TO fTxt1
                   FONT NEW $pFont4,12,1,204,0 TO fZagB
                   FONT NEW $pFont1,12,0,204,0 TO fTime
                   DIALOG FONT DEFAULT $pFont2,10,0,204 '"Arial"
                   DIALOG NEW PIXELS, 0,$AppTitle,tR,tD,%wW,%wH,%WS_POPUP OR %WS_VISIBLE _ '
                    OR %DS_SETFONT OR %WS_CLIPCHILDREN OR %WS_BORDER OR %WS_CAPTION _ 
                    OR %WS_SYSMENU OR %WS_DLGFRAME _
                    TO hDlg    ' Create a dialog box
                  '  ,%WS_EX_TOPMOST _
                   IF hDlg=0 THEN EXIT FUNCTION
                   fDlgEnd=%FALSE
                   CONTROL ADD LABEL,hDlg,%ID_S1,"G r a p h i c s   T e s t",10,12,320,20,0
                   CONTROL SET FONT hDlg,%ID_S1,fZagB
                   CONTROL ADD TEXTBOX, hDlg,%ID_S2,"", 10,40, 460,20,0
                   CONTROL SET FONT hDlg,%ID_S2,fTxt1 
                   CONTROL ADD TEXTBOX, hDlg,%ID_S3,"", 10,400,460,20,0
                   CONTROL SET FONT hDlg,%ID_S3,fTxt1 
                   CONTROL ADD TEXTBOX, hDlg,%ID_S4,"",350, 10,160,20,0
                   CONTROL SET COLOR hDlg,%ID_S4, -1,RGB(255,255,217)
                   CONTROL SET FONT hDlg,%ID_S4,fTxt1 
                   CONTROL ADD TEXTBOX, hDlg,%ID_S5,"", 10,430,460,20,0
                   CONTROL SET FONT hDlg,%ID_S5,fTxt1 
                   CONTROL ADD TEXTBOX, hDlg,%ID_S6,"", 10,460,460,20,0
                   CONTROL SET FONT hDlg,%ID_S6,fTxt1 
                   s5="#"
                   CONTROL ADD BUTTON,hDlg,%ID_OK,"OK",%wW-50,%wH-50,40,40
                   CONTROL ADD GRAPHIC, hDlg, %ID_GA, "GA", %ar, %ad, %aW, %aH, _
                    %SS_NOTIFY OR %WS_CHILD OR %WS_VISIBLE OR %SS_OWNERDRAW OR _
                    %WS_BORDER
                   DIALOG SHOW MODELESS hDlg, CALL D_CB
                   AWin = GetDlgItem(hDlg, %ID_GA)' Store the handle to the graphics window
                   GRAPHIC ATTACH hDlg, %ID_GA
                   GRAPHIC PAINT (0,0),RGB( 85, 255, 255)
                   GRAPHIC COLOR -1,RGB( 85, 255, 255)
                   GRAPHIC GET LOC TO xG, yG
                   CONTROL SET TEXT hDlg,%ID_S2,"Loc on the Screen: xG="+STR$(xG)+ _
                           ", yG="+STR$(yG)+", Hndl="+STR$(AWin)
                   GRAPHIC SET POS (20,4): GRAPHIC COLOR %MAGENTA: GRAPHIC SET FONT fZagl
                   GRAPHIC PRINT "Graphical Window"+STR$(%aW)+" x"+STR$(%aH)
                   GRAPHIC SET POS (12,40): GRAPHIC COLOR %BLACK: GRAPHIC SET FONT fTxt1
                   GRAPHIC PRINT ">";: GRAPHIC GET POS TO x,y: GRAPHIC SET FOCUS
                   GRAPHIC REDRAW
                   THREAD CREATE eThread(hDlg) TO hThread
                   hTimer = SetTimer(0,0,500,CODEPTR(Timer_Event))
                   lTimer=0: fThrClose=%FALSE: wTimer=0: fUnd=0: fI=0
                   DO                        ' Main cycle until fDialog is %TRUE
                    IF ISTRUE fTimer THEN wTimer=1: fTimer=%FALSE
                    IF fI=0 THEN ' Test for getting symbol
                      GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC INKEY$ TO sI
                      IF LEN(sI)>0 THEN fI=1
                    END IF
                    IF fI=1 THEN
                      CONTROL SET TEXT hDlg,%ID_S6,"LEN="+STR$(LEN(sI)): fI=2
                    END IF
                    DIALOG DOEVENTS
                   LOOP WHILE ISFALSE fDlgEnd
                   KillTimer 0, hTimer       ' Destroy the timer
                   DO: THREAD CLOSE hThread TO Result: SLEEP 50: LOOP UNTIL ISTRUE Result
                   DIALOG END hDlg
                  END FUNCTION

                  Comment


                  • #10
                    2Dave Biggs: Yeap, your program is working /although on the beginning of CASE 2 it's better to clear sTemp :laugh: /
                    I did patch up my sample - thanks for the heads-up.

                    Here are a couple of mods for insertion in your code. Doesn't address the main problem though (detecting the extended keys with Graphic Inkey$). Maybe if you could simplify your example to a minimum..?
                    Code:
                    SUB CurTime()
                      cDat1=DATE$: cDat2=MID$(cDat1,4,2)+"/"+MID$(cDat1,1,2)+"-"+MID$(cDat1,9,2)
                      cDat3=cDat2+" - "+TIME$
                    END SUB 
                    '------------------/
                     
                    CallBack Function TextBoxProc
                      Select Case As Long CbMsg
                        Case %WM_LButtonUp                                        '* sub class to catch these
                            s5=s5+"l": CONTROL SET TEXT hDlg,%ID_S5,s5
                        Case %WM_RButtonUp
                            s5=s5+"r": CONTROL SET TEXT hDlg,%ID_S5,s5            '*
                     
                        Case %WM_SYSKEYUP                                         ' Eat F10 (special key)
                            If CbWparam = %VK_F10 Then
                              Exit Function 
                            End If
                     End Select
                     Function = Callwindowproc(Getwindowlong(CbHndl, %GWL_USERDATA), CbHndl, CbMsg, CbWParam, CbLParam)
                    End Function
                    '------------------/
                     
                    '====================================================================
                    CALLBACK FUNCTION D_CB() AS LONG
                    '--------------------------------------------------------------------
                      LOCAL pT AS POINTAPI
                      SELECT CASE CB.MSG
                      Case %WM_INITDIALOG
                          ' set up subclass proc & record old proc add in %ID_GA userdata. (TT Colin Schmidt)
                          Setwindowlong Getdlgitem(CbHndl, %ID_GA), %GWL_USERDATA, _
                          SetWindowLong(GetDlgItem(CbHndl,  %ID_GA), %GWL_WNDPROC, CodePtr(TextBoxProc))
                     
                    CASE %WM_DESTROY
                       fDlgEnd=%TRUE
                    Rgds, Dave

                    Comment


                    • #11
                      Originally posted by Dave Biggs View Post
                      Here are a couple of mods for insertion in your code. Doesn't address the main problem though (detecting the extended keys with Graphic Inkey$).
                      Oh, thanks, I know it. I'd deleted such block just before put my code here. Although, that subclass was the mouse about.

                      Maybe if you could simplify your example to a minimum..?
                      It's about minimum. Although I can delete 10-20 strings with the fonts declarations etc.
                      That's the matter - I need write for realtime process and really need some threads, the real program has 3 windows... Since 1989 I tried to solve realtime problems on PowerBASIC solutions, usually successfull.
                      Have you any ideas, what's wrong in my example?

                      Comment


                      • #12
                        here...
                        Code:
                        IF fI=0 THEN ' Test for getting symbol
                            GRAPHIC ATTACH hDlg,%ID_GA: GRAPHIC INKEY$ TO sI
                            IF LEN(sI)>0 THEN fI=1
                          END IF
                        .. using GRAPHIC CONTROL, might you you need to ...
                        Code:
                        CONTROL SET FOCUS hDlg, %ID_GA
                        .. somewhere to get back the results of GRAPHICS INKEY$ ???

                        If that control is not focused, I don't see how it can ever get any keystrokes.

                        (I am not a DDT guy).

                        Also just in general, based on some threads we've had here, it might be a good practice to develop to do your GRAPHIC ATTACHs with a paired GRAPHIC DETACH when done.

                        I doubt it matters in this application since there is only one graphic but much like doing file OPENs paired with CLOSEs when done, or WinAPI Getxxx and Releasexxx functions in pairs, I think this might make some sense. Worth thinking about anyway.

                        MCM
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Originally posted by Michael Mattias View Post
                          If that control is not focused, I don't see how it can ever get any keystrokes.
                          Get my code, translate, and you'll see: it IS working, getting and understanding all keystrokes except extended.

                          it might be a good practice to develop to do your GRAPHIC ATTACHs with a paired GRAPHIC DETACH when done.
                          Much thanks, Michael, that you pay my attention on it. To my sorry, it don't solves the problem.

                          Yours, A.T.

                          Comment


                          • #14
                            It's definitely not working.

                            Maybe it has something to do with trying to GRAPHIC ATTACH to hdlg from within two separate thread contexts (I have no clue how GRAPHIC ATTACH is implemented).

                            While it 'seems' to work for regular keys, something is definitely wring with 'extended' keys like F1-F10 or home, delete, page up, etc.

                            Diagnosis: Broke.

                            Treatment: Contact PB support. (You do know this is not an official communications venue, right?)


                            MCM
                            Michael Mattias
                            Tal Systems Inc. (retired)
                            Racine WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              It's about minimum.
                              Well I managed to trim quite a bit more to avoid wasting effort on 'Red Herrings'.
                              This code does the same as the original though - Inkey$ only returns single characters.
                              Code:
                              #Debug Display ON
                              #COMPILE EXE
                              #DIM ALL
                              #REGISTER NONE
                              #INCLUDE "WIN32API.INC"
                               
                              %ID_S1       = 101
                              %ID_S6       = 105
                              %ID_GA       = 200
                               
                              FUNCTION WINMAIN (BYVAL hInstance AS DWORD, BYVAL hPrevInst AS DWORD, _
                                                BYVAL pCmdLine AS ASCIIZ PTR, BYVAL nCmdShow AS LONG) AS LONG
                               LOCAL hDlg AS DWORD
                               LOCAL sI AS STRING
                               LOCAL x, y, fI AS LONG
                               
                               DIALOG NEW PIXELS, 0,"Test graphics especially", , , 560, 540, %WS_POPUP OR %WS_VISIBLE _ '
                                              OR %DS_SETFONT OR %WS_CLIPCHILDREN OR %WS_BORDER OR %WS_CAPTION _
                                              OR %WS_SYSMENU OR %WS_DLGFRAME TO hDlg    ' Create a dialog box
                               IF hDlg=0 THEN EXIT FUNCTION
                               
                               CONTROL ADD LABEL,hDlg,%ID_S1,"G r a p h i c s   T e s t",10,12,320,20,0
                               CONTROL ADD TEXTBOX, hDlg, %ID_S6, "", 10,430,460,20,0
                               
                               CONTROL ADD GRAPHIC, hDlg, %ID_GA, "GA" ,22, 65, 460, 300, _
                                 %SS_NOTIFY OR %WS_CHILD OR %WS_VISIBLE OR %SS_OWNERDRAW OR %WS_BORDER
                               
                               DIALOG SHOW MODELESS hDlg
                               
                               GRAPHIC ATTACH hDlg, %ID_GA
                               GRAPHIC PAINT (0,0),RGB( 85, 255, 255)
                               GRAPHIC SET POS (20,4): GRAPHIC COLOR %MAGENTA,RGB( 85, 255, 255)
                               GRAPHIC PRINT "Graphic Control"
                               GRAPHIC SET POS (12,40): GRAPHIC COLOR %BLACK,RGB( 85, 255, 255)
                               GRAPHIC PRINT ">";: GRAPHIC GET POS TO x,y
                               GRAPHIC SET FOCUS
                               
                               DO
                                 GRAPHIC INKEY$ TO sI
                                 DIALOG DOEVENTS
                                IF LEN(sI)>0 THEN fI=1 : WinBeep 800,1
                                IF fI=1 THEN
                                  GRAPHIC PRINT IIF$(LEN(sI)=1, sI, RIGHT$(sI,1));
                                  DIALOG DOEVENTS
                                  CONTROL SET TEXT hDlg, %ID_S6, "LEN="+STR$(LEN(sI)) : fI=0
                                  DIALOG DOEVENTS : SLEEP 50 : CONTROL SET TEXT hDlg, %ID_S6, ""
                                END IF
                                DIALOG DOEVENTS
                               LOOP WHILE ISWIN(hDlg)
                               
                               DIALOG END hDlg
                              END FUNCTION
                              '------------------/
                              Looks like Inkey$ is broken for GRAPHIC CONTROLS.
                              (Or the docs should point out that extended keys are detected by Inkey$ in Graphic Windows only)
                              Rgds, Dave

                              Comment


                              • #16
                                Just reviving an old thread from 2001. Tried the examples and seems that PBWin version 9 still has the same bug with GRAPHIC INKEY$, ie. only returns single characters and not extended ones. This seems a pretty severe limitation for this command and obviously different from the documentation provided.

                                Peter

                                Comment


                                • #17
                                  Could you show compilable code that doesn't return the extended key codes?
                                  Rod
                                  I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                  Comment


                                  • #18
                                    Fiddling with some code of Gösta's
                                    Code:
                                    'PBWIN 9.00 - WinApi 05/2008 - XP Pro SP3
                                    #COMPILE EXE
                                    #DIM ALL
                                    #INCLUDE "WIN32API.INC"
                                    #INCLUDE "COMDLG32.INC"
                                    
                                    FUNCTION PBMAIN
                                      ERRCLEAR
                                        LOCAL hwin AS DWORD, s$
                                        GRAPHIC WINDOW "Testing", 100, 200, 200, 100 TO hWin
                                        GRAPHIC ATTACH hWin, 0
                                    g1:
                                        GRAPHIC INKEY$ TO s$
                                        IF LEN(s$) = 0 THEN GOTO g1 'no key pressed
                                        IF LEN(s$)=1 AND ASC(s$)<32 THEN
                                          ? "ASC"+FORMAT$(ASC(s$))
                                        ELSEIF LEN(s$)=1 THEN
                                          ? "String length=1 "+s$
                                        END IF
                                        IF LEN(s$)=2 THEN ? "String length=2!"+$CRLF+ FORMAT$(ASC(LEFT$(s$,1))) +$CRLF+ _
                                         "Extended key code"+ FORMAT$(ASC(RIGHT$(s$,1)))
                                    
                                        'GRAPHIC WINDOW END
                                        IF UCASE$(s$)<>"Q" THEN GOTO g1
                                        'dialog doevents
                                        ? "Inkey$ works" 'Never gets here
                                        GRAPHIC WINDOW END
                                    END FUNCTION 'Applikation beenden
                                    '
                                    Rod
                                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                    Comment


                                    • #19
                                      Thanks, yes seems to work but cannot quite see what the difference is betwen the two programs. If you set up a dialog and attach the graphics control as in David Biggs's program but run your INKEY$ detection and reporting section (ie. pasting in your program from line g1) then INKEY$ becomes again limited to single characters (a DIALOG DOEVENTS has to be added to the code).

                                      That said, GRAPHICS INKEY$ still has its problems that limit its use (these are very much shared with the PBCC version of INKEY$). These include failing to return the correct extended return code for <SHIFT>'ed non-character keys (eg. F1 return the code 59, but <SHIFT>F1 also returns 59 instead of 84). It also fails to respond to <ALT> key combination; <ALT>F1 should return 104. I do realise that Windows programs don't like the use of <ALT> keys, as they are reserved for the menu, but nevertheless it should still be possible for the application to intercept them first.

                                      This problem with INKEY$ was worked around in PBCC by also reading the INSHIFT value to find out whether <ALT>, <CONTROL> etc. were pressed at the same time.

                                      http://www.powerbasic.com/support/pb...ad.php?t=14596

                                      Alas INSHIFT is not provided in PBWin.

                                      Probably going to have to abandon INKEY$ and try to use CALLBACK to try to return the full set of return codes from the keyboard. As as Windows novice, this is proving horrible!

                                      Peter

                                      Comment


                                      • #20
                                        >Alas INSHIFT is not provided in PBWin.

                                        ==> GetAsynchKeyState() or maybe GetKeyState()

                                        Not sure which one you'd want to use in conjunction with GRAPHIC INKEY$. Try 'em.
                                        Michael Mattias
                                        Tal Systems Inc. (retired)
                                        Racine WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X