FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

CONTROLS

Change a control's name when a key is pressed


Try something like this.

LOCAL FN keyDown
  DIM KeyRecord (7)
  CALL GETKEYS(KeyRecord(0))
END FN = FN BITTST(VARPTR(KeyRecord(3)),13)

WINDOW 1, "button test", (3,41)-(509,338),1
BUTTON 1,_activeBtn,"Add Name", (10,30)-(120,50)
PRINT "Press + to end."

WHILE gProgramEnds = 0
  HANDLEEVENTS
  optKeyDown% = FN keyDown
  LONG IF optKeyDown%
    LONG IF gOptFlag% = _false
      BUTTON 1,_activeBtn,"Import Names"
      gOptFlag% = _ztrue
    END IF
  XELSE
    LONG IF gOptFlag% = _ztrue
      BUTTON 1,_activeBtn,"Add Name"
      gOptFlag% = _false
    END IF
  END IF
WEND

Al Staffieri Jr.


' this code shows how to do what you asked for --
' to change a button-label when the option-key is pressed.
' i think your code didn't work because
' the option key doesn't put a keypress event in the queue.
' bowerbird

COMPILE 0,_caseinsensitive
DIM ggetkeys%(32)
glabelup$="up label" : glabeldown$="label down"
glabel$=glabelup$
WINDOW 1,"",(0,0)-(600,400)
BUTTON 1,1,glabel$,(20,20)-(200,100)
END GLOBALS

CLEAR LOCAL FN dotimer
  CALL GETKEYS (ggetkeys%(0))
  option=FN BITTST(VARPTR(ggetkeys%(3)),13&)
  IF option=0 THEN option$="up" : ELSE option$="down"
  LONG IF option$="down" AND glabel$<>glabeldown$
    glabel$=glabeldown$
    BUTTON 1,1,glabel$
  XELSE
    LONG IF option$="up" AND glabel$<>glabelup$
      glabel$=glabelup$
      BUTTON 1,1,glabel$
    END IF
  END IF
END FN

ON TIMER (-15) FN dotimer : REM <= checks 4 times/second
DO
  HANDLEEVENTS
UNTIL 0

Bowerbird


You need to work in an ON EVENT function and not discriminate among events, i.e., check the state of the option key whenever your ON EVENT function is entered.

LOCAL FN DoEvent

  theEvent = {EVENT}
  thePoint;4 = EVENT+_evtMouse
  modKeys;2 = EVENT+_evtMeta
  optDown = modKeys AND _optionKey%

  LONG IF optDown
    LONG IF gOptFlag% = _false
      BUTTON 1,_activeBtn,"Import Names"
      gOptFlag% = _ztrue
    END IF
  XELSE
    LONG IF gOptFlag% = _ztrue
      BUTTON 1,_activeBtn,"Add Name"
      gOptFlag% = _false
    END IF
  END IF

END FN

Charlie