Announcement

Collapse
No announcement yet.

GRAPHIC WAITKEY$ and <TAB>

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

  • GRAPHIC WAITKEY$ and <TAB>

    GRAPHIC WAITKEY$ does not appear to detect the TAB key, which seems odd to me. Is there a reason for this?

    Code:
    #COMPILE EXE
    #DIM ALL
    
    FUNCTION PBMAIN () AS LONG
        LOCAL hGW AS DWORD
        LOCAL s AS STRING
    
        GRAPHIC WINDOW "", 300, 300, 300, 300 TO hGW
        GRAPHIC ATTACH hGW, 0
        GRAPHIC PRINT "press the TAB key"
        GRAPHIC WAITKEY$ TO s
        ? ASC(s), ASC(MID$(s,2))
        SLEEP 2000
    
    END FUNCTION

  • #2
    Tab key

    Same thing with GRAPHIC INKEY$
    Old QB45 Programmer

    Comment


    • #3
      It also seems that you can't use GRAPHIC INKEY$ for the numeric and period keys on the numeric keypad with the NumLock key OFF (but the NumLock key CAN be read).

      However, interestingly enough, with NumLock off, if you hold down the ALT key and press a series of numbers on the numeric keypad, it WILL return the character whose ASCII code is the series of numbers you pressed.

      Also, regarding the TAB key, if you press ALT TAB, the windows task switcher kicks in, but you still don't get a response from GRAPHIC INKEY$.

      Seems like Windows is intercepting these keys and getting in the way of GRAPHIC INKEY$ (and the other GRAPHIC input statements).

      Comment


      • #4
        <TAB> is a windows control key - "go to next control with WS_TABSTOP style."

        Maybe it's not supposed to be detectable for that reason.

        Probably can't get ALT+F4 (close current window) either.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Also, the right hand control key returns a code of its own (0,29) instead of modifying another key.

          Following MCM's comments above, this link http://msdn.microsoft.com/en-us/library/ms971323.aspx gives an insight into how M$ wants us to do it.

          The level at which the compiler gets keystrokes is compatible with this interface model.

          I'm not sure that an application using a PBCC GRAPHIC WINDOW is in fact a Windows application in the UI sense!

          Imperfect world, etc etc.

          Comment


          • #6
            Would still be a nice "remarks" in the help file under GRAPHIC IN[STAT|KEY$].

            Someone who actually uses these functions should probably send that in to [email protected]
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Tab Key

              Since it would be nice to be able to use the Tab Key in Graphic Console applications, we will have to learn to subclass it.
              I might try to do it today unless someone out there already know how to do it ?
              Old QB45 Programmer

              Comment


              • #8
                Originally posted by Guy Dombrowski View Post
                Since it would be nice to be able to use the Tab Key in Graphic Console applications, we will have to learn to subclass it.
                I might try to do it today unless someone out there already know how to do it ?
                Guy, you are nearly there already - WM_KEYDOWN or WM_KEYUP or WM_CHAR are the messages and %VK_TAB is the keycode. There are lots of egs in the fora, here's a likely one: http://www.powerbasic.com/support/pb...vk_tab+wm_char

                Comment


                • #9
                  >Since it would be nice to be able to use the Tab Key in Graphic Console applications

                  Um, then send that in as a New Feature Suggestion!

                  Look at Win/9 CC/5... a whole lot of new features to handle all the other keys! And why is that? Because prior to these releases you had to subclass to process ANY keys at all, and someone - or manyone - asked for easier handling!
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    Guy,

                    You'll need to subclass the Child of the Graphic Window - see examples here by Rick Angell..
                    http://www.powerbasic.com/support/pb...ad.php?t=38803
                    Last edited by Dave Biggs; 29 Oct 2008, 10:47 AM. Reason: sp
                    Rgds, Dave

                    Comment


                    • #11
                      Tab Key subclassed

                      Well,

                      It does work now.
                      I simply added the WM_CHAR test to my subclass code and it works like a charm.
                      But take care to insert your test before checking for the GRAPHIC INKEY$ = "" as the Null value will exit your loop before the TabKey can be verified.
                      Of course, your code should reset the TabKey flag after being used.

                      Here is the skeleton code to use if you want to play with a Subclassed Graphic Console

                      Code:
                      #COMPILE EXE
                      #CONSOLE OFF
                      #INCLUDE "Win32Api.inc"
                      DEFLNG a-z
                      GLOBAL GrDialogProc AS LONG
                      GLOBAL GrStaticProc AS LONG
                      GLOBAL mx AS LONG,my AS LONG    ' Mouse x and y
                      GLOBAL lb AS LONG,rb AS LONG    ' Left and right mouse button
                      GLOBAL mm AS LONG               ' Detect mouse movements
                      GLOBAL bg AS LONG,fg AS LONG    ' Background and foreground colors
                      GLOBAL wm AS LONG,mb AS LONG    ' Wheel mouse and middle button
                      GLOBAL TabKey AS LONG           ' Detect Tab Key
                      
                      FUNCTION GrDlgProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                      FUNCTION = CallWindowProc(GrDialogProc, hWnd, wMsg, wParam, lParam)
                      END FUNCTION
                      
                      FUNCTION GrProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                        LOCAL p AS pointapi
                        SELECT CASE wMsg
                          CASE %WM_CHAR
                            IF LO(WORD,wParam)=9 THEN TabKey=9                   ' Tab Key not caught by GRAPHIC INKEY$
                          CASE %WM_MOUSEMOVE
                            mm=1: mx=LO(WORD,lParam): my=HI(WORD,lParam)         ' Current Mouse X and Y Position in the graphic window
                          CASE %WM_LBUTTONDOWN
                            lb=1: FUNCTION=0: EXIT FUNCTION                      ' Left button pressed
                          CASE %WM_RBUTTONDOWN
                            rb=1: FUNCTION=0: EXIT FUNCTION                      ' Right button pressed
                          CASE %WM_MBUTTONDOWN
                            mb=1: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
                          CASE %WM_MOUSEWHEEL
                            wm=HI(WORD,wParam): IF wm>32768 THEN wm=-1 ELSE wm=1 ' Wheel turned (+)=up (-)=down
                            FUNCTION=0: EXIT FUNCTION
                        END SELECT
                       FUNCTION = CallWindowProc(GrStaticProc, hWnd, wMsg, wParam, lParam)
                      
                      END FUNCTION
                      Old QB45 Programmer

                      Comment


                      • #12
                        subclass + shift state

                        Thanks Guy!

                        I have tweaked your example to show shift state too, for any "printable" key shifted or unshifted.

                        In order to use the key combinations used in Notepad (for example) the extended keys both raw and shifted will also be needed, but "not tonight, Josephine".

                        Code:
                        ' using Guy Dombrowski's subclass proc to get key codes
                        ' slightly tweaked to return any keyboard code
                        ' combined with its shift state
                        #COMPILE EXE
                        #CONSOLE OFF
                        #INCLUDE "Win32Api.inc"
                        DEFLNG a-z
                        GLOBAL GrDialogProc AS LONG
                        GLOBAL GrStaticProc AS LONG
                        GLOBAL mx AS LONG,my AS LONG    ' Mouse x and y
                        GLOBAL lb AS LONG,rb AS LONG    ' Left and right mouse button
                        GLOBAL mm AS LONG               ' Detect mouse movements
                        GLOBAL bg AS LONG,fg AS LONG    ' Background and foreground colors
                        GLOBAL wm AS LONG,mb AS LONG    ' Wheel mouse and middle button
                        GLOBAL gKey AS LONG             ' keypress
                        
                        FUNCTION GrDlgProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                        FUNCTION = CallWindowProc(GrDialogProc, hWnd, wMsg, wParam, lParam)
                        END FUNCTION
                        
                        FUNCTION GrProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                              LOCAL p AS pointapi
                              SELECT CASE wMsg
                                  CASE %WM_CHAR
                                      IF 0 > getkeystate(%VK_SHIFT) THEN
                                          gKey = LO(WORD,wParam) OR &H40
                                      ELSE
                                          gKey = LO(WORD,wParam)
                                      END IF
                        
                                  CASE %WM_MOUSEMOVE
                                      mm=1: mx=LO(WORD,lParam): my=HI(WORD,lParam)         ' Current Mouse X and Y Position in the graphic window
                                  CASE %WM_LBUTTONDOWN
                                      lb=1: FUNCTION=0: EXIT FUNCTION                      ' Left button pressed
                                  CASE %WM_RBUTTONDOWN
                                      rb=1: FUNCTION=0: EXIT FUNCTION                      ' Right button pressed
                                  CASE %WM_MBUTTONDOWN
                                      mb=1: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
                                  CASE %WM_MOUSEWHEEL
                                      wm=HI(WORD,wParam): IF wm>32768 THEN wm=-1 ELSE wm=1 ' Wheel turned (+)=up (-)=down
                                      FUNCTION=0: EXIT FUNCTION
                              END SELECT
                           FUNCTION = CallWindowProc(GrStaticProc, hWnd, wMsg, wParam, lParam)
                        END FUNCTION
                        '-----------------------------------------------------
                        FUNCTION PBMAIN () AS LONG
                            LOCAL hGW AS DWORD
                            LOCAL s AS STRING
                            LOCAL hstatic AS DWORD
                        
                            GRAPHIC WINDOW "", 100, 100, 300, 300 TO hGW
                            hStatic = GetWindow(hGW, %GW_CHILD)                       ' Retrieve static handle of graphic window
                            GrStaticProc = SetWindowLong(hStatic, %GWL_WNDPROC, CODEPTR(GrProc)) ' Subclasses Graphic control
                            GRAPHIC ATTACH hGW, 0
                            GRAPHIC FONT "Courier New", 12
                            GRAPHIC PRINT "press a key or ESC to exit"
                            
                            DO
                                GRAPHIC SET POS (20, 60)
                                SELECT CASE gkey
                                    CASE 27
                                        GRAPHIC PRINT "Goodbye!                   "
                                        SLEEP 500
                                        EXIT LOOP
                                    CASE 0
                                        GRAPHIC PRINT "                           "
                                    CASE ELSE
                                        GRAPHIC PRINT "key was " + CHR$(gkey) + " (&H" + HEX$(gkey)+")"
                                        SLEEP 1000
                                END SELECT
                                gkey = 0
                                SLEEP 0
                            LOOP
                            GRAPHIC WINDOW END
                            SetWindowLong(hStatic, %GWL_WNDPROC, grstaticproc) ' Subclasses Graphic control
                        END FUNCTION

                        Comment


                        • #13
                          Tweak

                          Chris,

                          I could not make your tweak do anything at all and I had to terminate your program with the Task Manager ??
                          So I rewrote part of it and added the [x] window close button to make it eazier to shut down.
                          I also added a flag to prevent writing uselessly and hogging the CPU.
                          What is your last line meant to do ? I disabled it but it did not change anything. Futur need perhaps ?
                          The way it is setup now make it very handy to try differents graphic codes with the subclass technique.
                          Next step, the Arrow and Control Keys ?
                          Code:
                          ' Modification of Chris tweak
                          ' To show shift state
                          
                          #COMPILE EXE
                          #CONSOLE OFF
                          #INCLUDE "Win32Api.inc"
                          DEFLNG a-z
                          GLOBAL GrDialogProc AS LONG
                          GLOBAL GrStaticProc AS LONG
                          GLOBAL mx AS LONG,my AS LONG    ' Mouse x and y
                          GLOBAL lb AS LONG,rb AS LONG    ' Left and right mouse button
                          GLOBAL mm AS LONG               ' Detect mouse movements
                          GLOBAL bg AS LONG,fg AS LONG    ' Background and foreground colors
                          GLOBAL wm AS LONG,mb AS LONG    ' Wheel mouse and middle button
                          GLOBAL gKey AS LONG             ' keypress
                          
                          FUNCTION GrDlgProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                          FUNCTION = CallWindowProc(GrDialogProc, hWnd, wMsg, wParam, lParam)
                          END FUNCTION
                          
                          FUNCTION GrProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG) AS LONG
                                LOCAL p AS pointapi
                                SELECT CASE wMsg
                                    CASE %WM_CHAR
                                        IF 0 > getkeystate(%VK_SHIFT) THEN gKey = (LO(WORD,wParam) OR &H40) ELSE gKey = LO(WORD,wParam) ' Chris tweak
                                    CASE %WM_MOUSEMOVE
                                        mm=1: mx=LO(WORD,lParam): my=HI(WORD,lParam)         ' Current Mouse X and Y Position in the graphic window
                                    CASE %WM_LBUTTONDOWN
                                        lb=1: FUNCTION=0: EXIT FUNCTION                      ' Left button pressed
                                    CASE %WM_RBUTTONDOWN
                                        rb=1: FUNCTION=0: EXIT FUNCTION                      ' Right button pressed
                                    CASE %WM_MBUTTONDOWN
                                        mb=1: FUNCTION=0: EXIT FUNCTION                      ' Middle button pressed
                                    CASE %WM_MOUSEWHEEL
                                        wm=HI(WORD,wParam): IF wm>32768 THEN wm=-1 ELSE wm=1 ' Wheel turned (+)=up (-)=down
                                        FUNCTION=0: EXIT FUNCTION
                                END SELECT
                             FUNCTION = CallWindowProc(GrStaticProc, hWnd, wMsg, wParam, lParam)
                          END FUNCTION
                          '-----------------------------------------------------
                          FUNCTION PBMAIN () AS LONG
                              LOCAL hGW AS DWORD
                              LOCAL s AS STRING
                              LOCAL hstatic AS DWORD
                          
                              GRAPHIC WINDOW "Shift", 100, 100, 600, 600 TO hGW
                              hStatic = GetWindow(hGW, %GW_CHILD)                                  ' Retrieve static handle of graphic window
                              GrStaticProc = SetWindowLong(hStatic, %GWL_WNDPROC, CODEPTR(GrProc)) ' Subclasses Graphic control
                              GRAPHIC ATTACH hGW, 0
                              GRAPHIC FONT "Lucida Console", 12
                              GRAPHIC PRINT "press a key or ESC to exit"
                          
                              DO
                                GRAPHIC GET DC TO hgw: IF hgw=0 THEN END  ' Graphic Window has been closed
                                IF hkey<>gkey THEN  ' Write only if new data
                                  GRAPHIC SET POS (20, 60): GRAPHIC PRINT "                           "
                                  GRAPHIC SET POS (20, 60): GRAPHIC PRINT "key was " + CHR$(gkey) + " (&H" + HEX$(gkey)+")": SLEEP 100
                                  hkey=gkey: SLEEP 0  ' Flag to prevent writing uselessly
                                END IF
                               SLEEP 1
                              LOOP UNTIL gkey=27
                          
                             SetWindowLong(hStatic, %GWL_WNDPROC, grstaticproc) ' End Subclasses Graphic control 
                             GRAPHIC WINDOW END
                          END FUNCTION
                          Last edited by Guy Dombrowski; 29 Oct 2008, 06:50 PM.
                          Old QB45 Programmer

                          Comment


                          • #14
                            Guy, I downloaded it myself and tried again - works as it sould, CPU about 2%, no idea.
                            The last two lines should be the other way around, and the comment should say "remove subclassing"!

                            Comment


                            • #15
                              Chris,
                              I just edited my last post to add your corrections and I had forgotten to add a SLEEP in the loop so now the left CPU is now between 0% and 1%
                              Very funny that the program will not respond at all.
                              The bottom DO LOOP does not respond at all.
                              I will play some more with it to find why.
                              I also discovered the ITERATE command you use in your little editor. Very neat command to remove ugly GOTO...
                              I will study that code some more
                              Good night
                              Old QB45 Programmer

                              Comment


                              • #16
                                ugly GOTO...
                                ???
                                I've never seen an ugly GOTO in my all my programming days. Must be frame of reference.
                                Rod
                                In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                Comment


                                • #17
                                  Originally posted by Rodney Hicks View Post
                                  ???
                                  I've never seen an ugly GOTO in my all my programming days. Must be frame of reference.
                                  Ugly may be too pejorative a term, but ITERATE has the advantage that a label is not required, and thus results in "fewer parts", and we all know that "fewer parts" makes "better programs"!

                                  Comment


                                  • #18
                                    ITERATE is good for a lot of instances(most) for the very reason you say, but GOTO has been good to me over the years and I don't understand why some take a negative view of it. Mostly being facetious.
                                    Rod
                                    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                    Comment


                                    • #19
                                      I also discovered the ITERATE command you use in your little editor. Very neat command to remove ugly GOTO...
                                      ???

                                      If ITERATE is usable, there is no reason to use a GOTO, as the normal loop constructs (UNTIL, WHILE, FOR/NEXT, EXIT) plus at most an IF.... ELSE.. ENDIFwill handle it.
                                      Michael Mattias
                                      Tal Systems (retired)
                                      Port Washington WI USA
                                      [email protected]
                                      http://www.talsystems.com

                                      Comment


                                      • #20
                                        I found the same "weakness" of GRAPHIC INLEY$ etc.
                                        PB support's answer was in the line of a GUI not needing/getting those keys.
                                        It was not clear, though, if PB would possibly make changes to GRAPHIC INKEY$.

                                        In my opinion it would be very useful to have the same functionality with the
                                        GRAPHIC commands as with the Console INKEY$ and INSHIFT.

                                        Therefore I wrote two programs that provide those feature:
                                        GW_Inkey() and GW_Inshift().

                                        GW_Inkey() provides the same codes as INKEY$ (on my keyboard) except the numeric pad keys.
                                        Those could be added, though.

                                        GW_Inshift() returns the state of all shift keys, just like INSHIFT, except BIT 7 (=Enhanced keys).

                                        The two programs do not need subclassing, just a few API calls.
                                        They are part of the GrButtons.inc file (and used successfully for operating the buttons) in:
                                        http://www.powerbasic.com/support/pb...ad.php?t=39023

                                        Best regards,
                                        Gert.
                                        Gert Voland

                                        Comment

                                        Working...
                                        X