Announcement

Collapse
No announcement yet.

Disabling certain keys during a program

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

  • Disabling certain keys during a program

    Greetings ...

    NOTE: Solution to problem discussed herein is to be compatible with PowerBasic CC Version 5.00

    Is there a special routine that disables specific keys during a program ??

    In a test program I am working on, I have either WAITKEY$ or INKEY$ procedures at certain points, each requiring the press of specific letter, number or F-Keys. Here's one example ...
    Code:
    XzitKode=1
    LLoopix:
      NNQuiry=WAITKEY$
      IF NNQuiry=CHR$(0,63) THEN XzitKode=4: ' F-5 Key
      IF NNQuiry=CHR$(0,68) THEN XzitKode=9: ' F-10 Key
    IF XzitKode=1 THEN GOTO LLoopix
    Something quirky is happening. Whenever the Left Arrow key -- CHR$(0,75) -- is pressed, the program, which has three sets of menu choices (each in a different SUB), goes from whatever INKEY$/WAITKEY$ point it is at back to the second menu of choices. As you can see in the example, Left Arrow, CHR$(0,75) is -NOT- a choice. This is true for all of the program's INKEY$ or WAITKEY$ procedures.

    I tried adding this line to all the INKEY$/WAITKEY$ procedures
    Code:
    IF NNQuiry=CHR$(0,75) THEN NNuttin="":' NNuttin is a GLOBAL string that does nothng
    That didn't work. BTW -- The quirk happens on several machines, not just one.
    So, is there some special way to disable the Arrow Left key (or, when necessary, any other key) ??

    If yes, please reply below -- and remember that any solution offered must be compatible with PowerBasic CC version 5.00 !!

    Thanx-A-Lot, Frank

  • #2
    Frank

    This works perfectly for me

    Code:
    #COMPILE EXE
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
    DIM XzitKode AS LONG
    DIM nnQuiry AS STRING
    XzitKode=1
      NNQuiry=WAITKEY$
      IF NNQuiry=CHR$(0,63) THEN PRINT "f5"
      IF NNQuiry=CHR$(0,68) THEN PRINT "f10"
      IF NNQuiry=CHR$(0,75) THEN PRINT "left arrow"
    WAITKEY$
    END FUNCTION
    Latest PBCC, Windows 10

    You might like to try my silly little program to check this stuff out


    Code:
    FUNCTION PBMAIN
    DIM a AS STRING
    start:
    MOUSE ON
    MOUSE 3,DOUBLE,MOVE,UP,DOWN
    a$ = WAITKEY$
    CLS
    PRINT "a$ ";
    PRINT a$
    PRINT "LEN(a$) ";
    PRINT LEN(a$)
    PRINT "ASC(MID$(a$,1,1)) ";
    PRINT ASC(MID$(a$,1,1))
    PRINT "ASC(MID$(a$,2,1)) ";
    PRINT ASC(MID$(a$,2,1))
    PRINT "ASC(MID$(a$,3,1)) ";
    PRINT ASC(MID$(a$,3,1))
    PRINT "ASC(MID$(a$,4,1)) ";
    PRINT ASC(MID$(a$,4,1))
    GOTO start
    END FUNCTION
    Kerry

    [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
    Kerry Farmer

    Comment


    • #3
      Originally posted by Kerry Farmer View Post
      Frank

      This works perfectly for me
      Kerry
      Thank You

      Doesn't work for me -- also the extra WAITKEY$ means that I have to press any legit key twice, and that creates its own issue.

      Comment


      • #4
        Frank

        Not sure i understand what you mean

        The first Waitkey$ says - 'I am waiting for input'

        The Waitkey$ says 'I have printed out the result and you can look at it and then I am going to exit the program'

        All good??????

        Kerry

        [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
        Kerry Farmer

        Comment


        • #5
          Is this closer? Catches left arrow, does nothing.
          Code:
          #compile exe
          #compiler pbcc 5  '<<=== per request to limit to PBCC 5 (5.04 in my case)
          #dim all
          function pbmain () as long
            local XzitKode as long
            local nnQuiry as string
            XzitKode=1
            LLoopix:
            NNQuiry=waitkey$
            select case NNQuiry
              case chr$(0,63)
                ? "f5"
              case chr$(0,68)
                ? "f10"
              case chr$(0,75)
                goto LLoopix ' do nothing on left arrow
              case chr$( 27)
                exit function 'escape key to exit program
            end select
            goto LLoopix
          end function
          Cheers,
          Dale

          Comment


          • #6
            Kerry, Did not mean to cut you off.

            From the code we've (all) used I do not think there is a difference between versions 5 and 6. I have both, so going with 5 was not a problem.

            Cheers,
            Dale

            Comment


            • #7
              Originally posted by Dale Yarker View Post
              Is this closer? Catches left arrow, does nothing
              Cheers,
              THAT WORKED! Should've thought of trying that to start with -- Thank You, Dale!

              UPDATE

              Have since found out that the true problem was a coding sequence in the second menu of the program (There are three such menus in the whole program). One simple added step fixed everything.

              Comment


              • #8
                Originally posted by Dale Yarker View Post
                Kerry, Did not mean to cut you off.

                From the code we've (all) used I do not think there is a difference between versions 5 and 6. I have both, so going with 5 was not a problem.

                Cheers,
                Not even the remotest problem Dale.

                I do not keep old PB versions and I was interested in the question.

                All good
                [I]I made a coding error once - but fortunately I fixed it before anyone noticed[/I]
                Kerry Farmer

                Comment

                Working...
                X