Announcement

Collapse
No announcement yet.

a few ?s - waitkey$ & mouse - and stops

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

  • a few ?s - waitkey$ & mouse - and stops

    OK... I'm finding the Graphic Window helpful but missing a couple things.

    1) How can I read for mouse moves (or clicks) AND keyboard strokes? It seems I can only do one or the other.
    I plotted stock prices on a window and I'm using Graphic Waitkey$ to check for key strokes, but I'd like to concurrently see if the mouse was moved or clicked.

    2) I'm new to PB/CC and used to an 'interpretive' world.
    Is there a way to find out where a program is "waiting"? Sometimes I can't tell which routine is active and stopping to program in a bunch of stops is time consuming (but what I've been doing).

    Thanks!

  • #2
    Doug:

    A very simple example of mouse clicks and cursor keys capture:

    a single click or Up/Down cursor key stroke moves de focus
    a double click or Enter key makes selection

    Code:
    #COMPILE EXE
    #CONSOLE OFF
    DEFLNG a-z
     
    GLOBAL OPS$(),clk&,xm!,ym!
    GLOBAL CarH,CarW,Sk AS DOUBLE
    GLOBAL I%,NO%,XS%,YS%,ST%,G%,hh&
     
    FUNCTION PBMAIN () AS LONG
     DIM OPS$(4)
     DESKTOP GET CLIENT TO PixW,PixH
     x1=0
     y1=0
     x2=PixW
     y2=PixH
     DESKTOP GET SIZE TO WinX,WinY
     Caption$="SIMPLE"
     GRAPHIC WINDOW caption$,x1,y1,x2,y2 TO hwin
     GRAPHIC ATTACH hwin,0,REDRAW
     GRAPHIC SET LOC -3,0
     GRAPHIC CLEAR RGB(220,223,220)
     GRAPHIC COLOR %BLACK,RGB(220,223,220)
     GRAPHIC WIDTH 2
     GRAPHIC BOX(10,10)-(WinX-10,WinY-60),,RGB(128,128,128)
     FONT NEW "Courier New",20,0,0,0,Sk TO fnt1
     GRAPHIC SET FONT fnt1
     GRAPHIC CHR SIZE TO CarW,CarH
     MaxCol=PixW/CarW
     MaxRow=PixH/CarH
     OPS$(1)="Option 1"
     OPS$(2)="Option 2"
     OPS$(3)="Option 3"
     OPS$(4)="Exit    "
     NO%=4
     XS%=475
     YS%=25
     G%=1
     ST%=40
     DO
      CALL MENUV(NO%,XS%,YS%,OP$(),G%,T%)
      GRAPHIC COLOR %RED,RGB(220,223,220)
      GRAPHIC SET POS(XS%,YS%+ST%*NO%+50)
      SELECT CASE G%
       CASE 1
        GRAPHIC PRINT "Your selection was "+OPS$(1)
       CASE 2
        GRAPHIC PRINT "Your selection was "+OPS$(2)
       CASE 3
        GRAPHIC PRINT "Your selection was "+OPS$(3)
       CASE 4
        EXIT LOOP
      END SELECT
      GRAPHIC REDRAW
     LOOP
    END FUNCTION
     
    SUB MENUV(NO%,XS%,YS%,OP$(),G%,T%)
     DO
      DO UNTIL clk&=0                           'CLEAR ALL PREVIOUS CLICKS
       GRAPHIC WINDOW CLICK TO clk&,xm!,ym!
      LOOP
      CALL OPTIONS(XS%,YS%,NO%)
      GRAPHIC WINDOW CLICK TO clk&,xm!,ym!      'MOUSE CLICKS; SINGLES/DOUBLES
      GRAPHIC INKEY$ TO D$                      'CURSOR KEYS
      IF clk& THEN
       IF (xm!>XS% AND xm!<XS%+150) AND (ym!>YS% AND ym!<YS%+ST%*NO%)THEN
        G%=1+(ym!-YS%)\ST%
        IF clk&=2 THEN D$=CHR$(13)
       END IF
      END IF
      IF D$=CHR$(0,72) THEN
       IF G%>1 THEN
        DECR G%
       ELSE
        G%=NO%
       END IF
      ELSEIF D$=CHR$(0,80) THEN
       IF G%<NO% THEN
        INCR G%
       ELSE
        G%=1
       END IF
      ELSEIF D$=CHR$(0,68) THEN
       T%=1
       EXIT LOOP
      ELSEIF D$=CHR$(13) OR FLG%=1 THEN
       CALL OPTIONS(XS%,YS%,NO%)
       SLEEP 10
       EXIT LOOP
      END IF
     LOOP
    END SUB
     
    SUB OPTIONS(XS%,YS%,NO%)
     FOR I%=1 TO NO%
      IF I%=G% THEN
       GRAPHIC COLOR %RED,RGB(220,223,220)
      ELSE
       GRAPHIC COLOR %BLACK,RGB(220,223,220)
      END IF
      GRAPHIC SET POS(XS%,YS%+ST%*(I%-1)+4)
      GRAPHIC PRINT OPS$(I%)
      GRAPHIC REDRAW
     NEXT
    END SUB
    Last edited by Manuel Valdes; 2 May 2009, 10:32 PM.

    Comment

    Working...
    X