Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

Detecting and changing Num Lock

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

  • Detecting and changing Num Lock

    Is it possible to detect when a user presses the Num lock key
    in PB 3.5? I want to be able to disable the switching of Num
    Lock off. I also would like to know how a key like this can
    be monitored for a key press.

    Rick


    ------------------
    mailto:[email protected][email protected]</A>

  • #2
    Yes and no. At any time, you can check the BIOS data area to see if NumLock is on, and you can easily toggle it on or off.

    But to detect when the key is pressed, you must write your own keyboard handler. You can write a small one in assembler that hooks the keyboard interrupt to intercept that keypress and then allows the regular keyboard interrupt handler to do its job. Or you can completely replace the keyboard handler with your own.

    The July 1997 issue of BASICally Speaking contained an article about replacing the keyboard interrupt handler, including PowerBASIC source code (with some inline assembler, which is unavoidable). You can download the code for free from our web site at http://www.infoms.com/archives.htm . You can also purchase the back issue for $4.00 from our online store.

    Alan Earnshaw
    Editor and Publisher, BASICally Speaking


    ------------------
    Alan C. Earnshaw
    Information Management Systems, Inc.
    http://www.infoms.com
    Alan C. Earnshaw
    Information Management Systems, Inc.
    http://www.infoms.com

    Comment


    • #3
      Here are some routines I have used.
      Dave.
      Code:
      %RightShift  = 1
      %LeftShift   = 2
      %Control     = 4
      %Alt         = 8
      %ScrollLock  = 16
      %NumLock     = 32
      %CapsLock    = 64
      %Insert      =128
      
      %Keyread   =0
      %Keyset    =1
      %Keyunset  =2
      %Alloff    =3
      
      FUNCTION KeyReg(BYVAL Mask?,BYVAL Action?)
            DIM X AS LOCAL BYTE PTR
            X=1047
            SELECT CASE Action?
            CASE %Keyset
               @[email protected] OR Mask?
            CASE %Keyunset
               @[email protected] AND NOT Mask?
            CASE %AllOff
               @X=0?
            END SELECT
            [email protected]
      END FUNCTION
      
      FUNCTION Ispressed(BYVAL Mask?)
               FUNCTION=0
               IF (KeyReg(0,%KeyRead) AND Mask?)=Mask? THEN FUNCTION=1
      END FUNCTION
      
      SUB SetKeyReg(BYVAL Mask?)
          KeyReg Mask?,%KeySet
      END SUB
      
      SUB UnsetKeyReg(BYVAL Mask?)
          KeyReg Mask?,%KeyUnSet
      END SUB
      
      SUB ClearKeyReg
          KeyReg 0,%AllOff
      END SUB
      
      'Set some keys
       SetKeyReg %CapsLock+%Numlock+%ScrollLock
       LOCATE 2,2
       PRINT "Setting some keys, Press NumLock to see what happens"
       PRINT "[Esc] TO EXIT"
      DO UNTIL INKEY$=CHR$(27)
        LOCATE 5,30
        PRINT KeyReg(0,%KeyRead);"   "
      LOOP
      
      'Unset all keys
       ClearKeyReg
       LOCATE 2,2
       PRINT "Unsetting All keys,Try some on                 "
       PRINT "[Esc] TO EXIT"
      DO UNTIL INKEY$=CHR$(27)
        LOCATE 5,30
        PRINT KeyReg(0,%KeyRead);"   "
      LOOP
      ------------------
      Dave.

      You're never too old to learn something stupid.

      Comment


      • #4
        Thanks people. That did the trick.

        Rick


        ------------------
        mailto:[email protected][email protected]</A>

        Comment

        Working...
        X