Post Reply 
How to use MOUSE
02-25-2020, 04:05 AM
Post: #4
RE: How to use MOUSE
The code I posted was just a subset of an idea, the 'Error' is due to the variable MK_in not being declared.

Here's a slightly more developed example that will run. NOTE it is intentionally designed to handle only 'click' events from the touch screen, event type 3. I have found this to be very suitable for GUI applications, with CASE structures to handle any and all possible inputs from the screen or keyboard.

Code:
#pragma mode( separator(.,;) integer(h32) )

// sub-routines
GetMK_in();
FlushKeysMouse();
ClearMouse();

// globals
MK_in,MK_mx,MK_my;

EXPORT IO_test()
BEGIN
  RECT_P();
  REPEAT
    TEXTOUT_P("Touch Screen or use Keys",G0,2,1,3,#000000h);
    DRAWMENU("","","","","","EXIT");
    GetMK_in();
    RECT_P();
    IF TYPE(MK_in)==0 THEN // key was pressed
      TEXTOUT_P("Pressed Key: "+STRING(MK_in),G0,2,20,3,#000000h);
    ELSE // must have been touch screen
      TEXTOUT_P("Touched Screen X:"+STRING(B→R(MK_mx))+" Y:"+STRING(B→R(MK_my)),G0,2,20,3,#000000h);
      IF MK_my>219 THEN // menu area
        IF MK_mx>264 THEN // button 6
          MK_in:=4; // set to ESC key
        END;
      END;
    END;
  UNTIL IFTE(TYPE(MK_in)==0,MK_in==-1 OR MK_in==4,0);
END;

GetMK_in()
BEGIN
  REPEAT
    IFERR MK_in:=WAIT(-1); THEN // ON key was pressed
      MK_in:=4; // set to ESC key
      FlushKeysMouse(); // necessary for multi-layering
    END;
  UNTIL TYPE(MK_in)==0 OR IFTE(SIZE(MK_in)>1,MK_in(1)==3,0);
  ClearMouse();
  IF TYPE(MK_in)==6 THEN // list
    MK_mx:=MK_in(2);
    MK_my:=MK_in(3);
  END;
END;

// get all keys and mouse events out of the system
FlushKeysMouse()
BEGIN
  LOCAL j,ksum;
  REPEAT
    ksum:=0;
    FOR j FROM 0 TO 50 DO // seems like a clumsy way to accomplish task
      ksum:=ksum+ISKEYDOWN(j);
    END;
  UNTIL ksum==0;
  ClearMouse();
END;

ClearMouse()
BEGIN
  LOCAL m;
  REPEAT
    m:=MOUSE();
  UNTIL SIZE(m(1))==0;
END;
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
How to use MOUSE - cahlucas - 02-24-2020, 10:46 PM
RE: How to use MOUSE - Jacob Wall - 02-25-2020, 12:05 AM
RE: How to use MOUSE - cahlucas - 02-25-2020, 03:07 AM
RE: How to use MOUSE - Jacob Wall - 02-25-2020 04:05 AM
RE: How to use MOUSE - cahlucas - 02-26-2020, 10:37 PM
RE: How to use MOUSE - cahlucas - 02-26-2020, 09:39 PM
RE: How to use MOUSE - Giancarlo - 02-28-2020, 06:18 PM
RE: How to use MOUSE - cahlucas - 02-29-2020, 02:27 AM



User(s) browsing this thread: 1 Guest(s)