Announcement

Collapse
No announcement yet.

Keys Esc Del Rtrn

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

  • Keys Esc Del Rtrn

    Please, how do I detect keydown for any of Escape, Delete, Return ?

  • #2
    this will compile with PB Win 8.04

    Code:
    #COMPILE EXE
    #DIM ALL
    
    #IF NOT %DEF(%WINAPI)
        #INCLUDE "WIN32API.INC"
    #ENDIF
    
    %IDD_DIALOG1  =  101
    %IDC_TEXTBOX1 = 1001
    %IDC_LABEL1 = 1002
    
    DECLARE CALLBACK FUNCTION ShowDIALOG1Proc()
    DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
    
    GLOBAL gOrigEditProc AS DWORD
    
    FUNCTION PBMAIN()
        ShowDIALOG1 %HWND_DESKTOP
    END FUNCTION
    
    FUNCTION subClassEditProc(BYVAL hWnd AS DWORD, BYVAL wMsg AS LONG, BYVAL wParm AS DWORD, BYVAL lParm AS DWORD) AS LONG
        ' Pass the message on to the original window procedure
        SELECT CASE wMsg
            CASE %wm_keyup
                SELECT CASE wparm
                    CASE %VK_TAB
                        CONTROL SET TEXT getparent(hWnd), %IDC_LABEL1, "TAB"
                    CASE %VK_ESCAPE
                        CONTROL SET TEXT getparent(hWnd), %IDC_LABEL1, "ESC"
                    CASE %VK_RETURN
                        CONTROL SET TEXT getparent(hWnd), %IDC_LABEL1, "RET"
                    CASE ELSE
                        CONTROL SET TEXT getparent(hWnd), %IDC_LABEL1, ""
                END SELECT
        END SELECT
        FUNCTION = CallWindowProc(gOrigEditProc, hWnd, wMsg, wParm, lParm)
    
    END FUNCTION
    
    CALLBACK FUNCTION ShowDIALOG1Proc()
    
        SELECT CASE AS LONG CBMSG
            CASE %WM_INITDIALOG
                gOrigEditProc = SetWindowLong(getdlgitem(CBHNDL, %IDC_TEXTBOX1), _
                                %GWL_WNDPROC, CODEPTR(subClassEditProc)) 'subclass
    
            CASE %WM_NCACTIVATE
                STATIC hWndSaveFocus AS DWORD
                IF ISFALSE CBWPARAM THEN
                    hWndSaveFocus = GetFocus()
                ELSEIF hWndSaveFocus THEN
                    SetFocus(hWndSaveFocus)
                    hWndSaveFocus = 0
                END IF
            CASE %WM_COMMAND
                SELECT CASE AS LONG CBCTL
                    CASE %IDC_TEXTBOX1
    
                END SELECT
        END SELECT
    END FUNCTION
    
    FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG
        LOCAL lRslt AS LONG
        LOCAL hDlg  AS DWORD
    
        DIALOG NEW hParent, "Catch edit Keystrokes", 167, 119, 201, 121, %WS_SYSMENU TO hDlg
        CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTBOX1, "", 5, 5, 85, 45
        CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "",95, 5, 85, 15
        DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt
        FUNCTION = lRslt
    END FUNCTION

    Comment


    • #3
      Wow! A reply in 31 minutes ! Thanks, Chris. You've given me a lot to think about. My first guess is that I'll be able to handle KeyDown from now on. You're a star !

      Comment


      • #4
        FWIW, most software which looks for key-presses looks for the UP event rather than the DOWN event.

        (Because holding the key down can generate multiple DOWN events).
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Thanks, Michael. Chris' code detected keyup, as you suggest. I confess I hadn't noticed, and, furthermore, I've been detecting keydown for years. Nobody complained, but, now that you make me think about it, yes, of course you're right. Powerful stuff, this Forum business !

          Comment


          • #6
            >I confess I hadn't noticed

            Real Users DO hold the keys down too long.

            Primarily they do this for the same reason they hit the keys harder or more than once: it makes it go faster.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              FWIW, this IS documented under the WM_KEYDOWN notification message in the SDK:
              lParam
              Specifies the repeat count, scan code, extended-key flag, context code, previous key-state flag, and transition-state flag, as shown in the following table.
              0-15
              Specifies the repeat count for the current message. The value is the number of times the keystroke is autorepeated as a result of the user holding down the key. If the keystroke is held long enough, multiple messages are sent. However, the repeat count is not cumulative.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                I'm red with shame ! What is this SDK that people talk about ? All I have is PBWin 8.04. You'll probably think me a complete beginner. Yet I started in 1958 with Ferranti Atlas, then IBM360 Assembler, PL1, TurboPascal, VB and now PB - which I rather like. Yet somehow SDK escaped me.

                Comment


                • #9
                  SDK is the programming style using the windows APIs exclusively, eschewing the PB extensions like the CONTROL.. and DIALOG... stuff. Often the two styles are mixed, though as you might expect there are hard line adherents of each style out there too.

                  Comment


                  • #10
                    Ralph,
                    I'm red with shame ! What is this SDK that people talk about ? All I have is PBWin 8.04. You'll probably think me a complete beginner. Yet I started in 1958 with Ferranti Atlas, then IBM360 Assembler, PL1, TurboPascal, VB and now PB - which I rather like. Yet somehow SDK escaped me.
                    Reply With Quote
                    Don't feel bad...there are MANY of us VB converts here (some call us "VB-Refugees" but nomatter)

                    When in doubt, think of "SDK" as "API" or dll's, and think of DDT as "On_KeyDown" concepts

                    For me the only argument I have with PB is (unfortunately I can not find a "Sarcastic" emoticon) that they actually give us both the power AND the ease of PB with DDT commands

                    Shame on them for teaching me the differences without my knowing

                    PB was the 1st to simply explain to me what VB just did by default for me withtout understanding why or how. T
                    t
                    he only side of "Both Camps" is what suits you at the point you understand, and PB gives you both (I kinda like that), so you can learn later.

                    aka...basic "Mouse_Down" vs "Mouse_Up" vs "Mouse_Click" in PB can show you really whats happening behind the scenes (I will use DDT for example), or the same using API (SDK) for "What happens? for when I click down?, how long? Do I click up? kinda concept)
                    Engineer's Motto: If it aint broke take it apart and fix it

                    "If at 1st you don't succeed... call it version 1.0"

                    "Half of Programming is coding"....."The other 90% is DEBUGGING"

                    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                    Comment


                    • #11


                      Sources of SDK / Windows API documentation:

                      MSDN Library online: http://msdn2.microsoft.com/en-us/Library
                      Microsoft Platform SDK CD (low cost) - order here: http://www.qmedia.ca/launch/psdk.htm
                      (Funky order form asks for a 10 digit phone number whatever your country! Use 123-456-7890 )

                      Download Windows 32-bit API help file: http://www.powerbasic.com/files/pub/mstools/Win32.zip
                      That's an old reference but still usable while waiting for your CD..
                      Rgds, Dave

                      Comment


                      • #12
                        God bless you, Dave Biggs ! That "old reference" is just what I needed. It's fine for my occasional foray into windows programming. With a bit of practice I could get to enjoy this !

                        Comment

                        Working...
                        X