Post Reply 
GETKEY
04-06-2022, 07:50 PM (This post was last modified: 04-06-2022 07:50 PM by matalog.)
Post: #1
GETKEY
Am I using GETKEY wrong here? Why does each keypress not get registered?

Code:
EXPORT Keytest
BEGIN
  LOCAL K:=0;
  LOCAL X:=0;
  LOCAL Y:=0;
  RECT_P();
REPEAT
  K:=GETKEY;
  IF K>(-1) THEN
    TEXTOUT_P(K,X,Y);
    X:=X+16;
      IF X>300 THEN
      Y:=Y+20;
      X:=0;
      END;
  END;
UNTIL ISKEYDOWN(4)=1;
END;
Find all posts by this user
Quote this message in a reply
04-07-2022, 02:59 AM
Post: #2
RE: GETKEY
I found WAIT(-1) was more suitable for most UI purposes. The code below is an example to check for keys and touch screen input, hope it helps.
Code:
#pragma mode( separator(.,;) integer(h32) )
// support routines
ResetTExit();
GetMK_in();
FlushKeysMouse();
ClearMouse();

// global variables
TExit:=2; // number of minutes before auto exit
TExit_count; // timeout tracker
MK_in,MK_mx,MK_my; // input variable and touch input x and y coordinates

EXPORT TESTUI()
BEGIN
  LOCAL my_str:="",exit_cond:=0;
  TExit_count:=0; // initialize auto exit counter
  REPEAT
    RECT_P(); // clear the screen
    TEXTOUT_P("TESTUI",G0,0,0); // some static text
    TEXTOUT_P(my_str,G0,0,50);
    DRAWMENU("","","","","Cancel","OK"); // basic menu
    GetMK_in(); // get input
    IF TYPE(MK_in)==0 THEN // keyboard input
      IF MK_in==-1 THEN // timeout after 60 seconds
        TExit_count:=TExit_count+1; // increment the exit counter
        my_str:="Exit counter is at " + STRING(TExit_count);
      ELSE
        ResetTExit(); // input was provided so clear the exit counter
        CASE
          IF MK_in==19 THEN // backspace
            MSGBOX("Exit condition met");
            exit_cond:=1;
          END;
          IF MK_in==30 THEN // ENTER
            my_str:="ENTER was pressed";
          END;
          IF MK_in==400 THEN // timed out
            MSGBOX("Timed out");
            exit_cond:=1;
          END;
          DEFAULT
          my_str:="Key " + STRING(MK_in) + " was pressed";
        END;
      END;
    ELSE // touch input
      CASE
        IF MK_my>219 THEN // menu
          CASE
            IF 265>MK_mx>212 THEN // Cancel
              MSGBOX("Exit condition met");
              exit_cond:=1;
            END;
            IF MK_mx>264 THEN // OK
              my_str:="OK menu button was touched";
            END;
            DEFAULT
            my_str:="Menu area left of cancel was touched";
          END;
        END;
        DEFAULT // above menu area
        my_str:="X: " + STRING(B→R(MK_mx)) + "  Y: " + STRING(B→R(MK_my));
      END;
    END;
  UNTIL exit_cond;        
END;

ResetTExit()
BEGIN
  IF TYPE(MK_in)==0 THEN
    IF MK_in<>400 THEN
      TExit_count:=0;
    END;
  END;
END;

GetMK_in()
BEGIN
  IF TExit_count==TExit THEN
    MK_in:=400;
  ELSE
    REPEAT
      IFERR MK_in:=WAIT(-1); THEN
        MK_in:=4;
        FlushKeysMouse();
      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);
      TExit_count:=0;
    END;
  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
      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
04-07-2022, 07:52 PM
Post: #3
RE: GETKEY
That is a brilliant program. Thanks for sharing it.
Find all posts by this user
Quote this message in a reply
Post Reply 




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