Post Reply 
MOUSE command CLICK type
01-25-2018, 09:59 PM
Post: #1
MOUSE command CLICK type
Hello,
with the following code i am able to detect the key (the ENTER key in this example) to stop the program and some gestures on the touch screen.

What is making me mad is that i can detect the DRAG, the ROTATE and STRETCH but I am not able to detect the simple CLICK!

In reality this is not true since, when i click on the menu RUN to execute the program, it automatically detect a CLICK and then, for the rest of execution i am not able to reproduce again.

At the moment i am interested in the single CLICK not the LONG one...

Code:

EXPORT MAUZ()
BEGIN
  LOCAL T,X,Y;
  DIMGROB(G1,320,220,RGB(255,120,255));
  LINE_P(G1,0,0,400,220,RGB(0,255,255));
  LINE_P(G1,0,220,400,0,RGB(0,255,255));

 WHILE ISKEYDOWN(30)≠1 DO  // STOP ON PRESS ENTER KEY
 BLIT_P(G1,0,0,320,220); 
 T:=MOUSE();
    IF SIZE(T(1)) THEN
      IF T(1,5)==1 THEN  //CLICK DOESN'T WORK
        X:=B→R(T(1,1)-T(1,3));
        Y:=B→R(T(1,2)-T(1,4)); 
        TEXTOUT_P("X= " + X,G0,10,10);
        TEXTOUT_P("Y= " + Y,G0,10,30);
        TEXTOUT_P(B→R(T(1)),G0,70,20);   
        WAIT(3);
      END;
      IF T(1,5)==2 THEN //2 DRAG WORKS
        X:=B→R(T(1,1));
        Y:=B→R(T(1,2)); 
        TEXTOUT_P("ΔX= " + X,G0,10,10);
        TEXTOUT_P("ΔY= " + Y,G0,10,30);
        TEXTOUT_P(B→R(T(1)),G0,70,20);
        WAIT(3);
      END;
      IF T(1,5)==3 THEN //3 STRETCH
        X:=B→R(T(1,1));
        Y:=B→R(T(1,2)); 
        TEXTOUT_P("X= " + X,G0,10,10);
        TEXTOUT_P("Y= " + Y,G0,10,30);
        TEXTOUT_P(B→R(T(1)),G0,70,20);
        WAIT(3);
      END;
      IF T(1,5)==4 THEN //4 ROTATE
        X:=B→R(T(1,1));
        Y:=B→R(T(1,2)); 
        TEXTOUT_P("X= " + X,G0,10,10);
        TEXTOUT_P("Y= " + Y,G0,10,30);
        TEXTOUT_P(B→R(T(1)),G0,70,20);
        WAIT(3);
      END;
      IF T(1,5)==5 THEN //5 LONG CLICK
        X:=B→R(T(1,1));
        Y:=B→R(T(1,2)); 
        TEXTOUT_P("X= " + X,G0,10,10);
        TEXTOUT_P("Y= " + Y,G0,10,30);
        TEXTOUT_P(B→R(T(1)),G0,70,20);
        WAIT(3);
      END;

    END;
 END; //FINE WHILE
END;

Any hint?

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-25-2018, 10:37 PM
Post: #2
RE: MOUSE command CLICK type
There are 2 ways to program interfaces, the easy one and the difficult one so to speak.
1 ° Event-based: WAIT (-1)
It recognizes screen and keyboard, it does not execute instructions if an event or 60s does not occur. (Single key press, click, long click, drag, rotate, zoom)
2 ° Based on fixed cycles: WAIT (.005) ?, MOUSE, GETKEY, |ISKEYDOWN|
The recognition algorithm must be programmed, long click not implemented.

The most recommended is to use mainly WAIT (-1), is it necessary to use mode 2?
You can use both ways, in order to cover all the needs, WAIT (-1) usually fulfills everything necessary unless it is something similar to a GAME.

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-25-2018, 11:40 PM
Post: #3
RE: MOUSE command CLICK type
Hello Carlos,
thanks for your feedback. In reality i tried to work with MOUSE since i tried to work with the WAIT(-1) command with no luck as well.
With WAIT i am able to detect the menu Keys, the CLICK, but i am not able to detect the MOVE (the direction of MOVE) since i'd like to understand where the user is moving the finger...

Another code snippet...

Code:


EXPORT SoftMenu_TOUCH_2_TEST()
BEGIN
 //STARTVIEW(−1);
 DRAWMENU("ONE","TWO","THREE","FOUR","FIVE","SIX");
 LOCAL inp, ret:=1;

 WHILE ret≠0 DO
   inp:=WAIT(-1);
   IF TYPE(inp)≠6 
     THEN RETURN inp; //RETURN KEY CODE
     ret:=0;
   ELSE  //TOUCH SECTION
     CASE
       IF inp(1)==1 THEN RETURN B→R(inp); ret:=0; END;
       IF inp(1)==3 THEN //CLICK
         IF inp(3)>#220d THEN 
            RETURN (1+IP(inp(2)*6/320));
            ret:=0;
         ELSE
           RETURN "CLICK UPPER AREA"; 
           ret:=0;
         END;
       END;
     DEFAULT
     END;  // END OF CASE (TOUCH)
   END;    // END OF IF TYPE
 END;      // END OF WHILE
END;

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-26-2018, 12:30 AM
Post: #4
RE: MOUSE command CLICK type
The screen events by WAIT (-1) are not unique, a behavior can have up to 3 values in buffer, it explores the values that each action returns, I also see your code a little messy, the conditionals must be located just where you are going to use it , it is not convenient at all to use returns and then compare them again, unless this code is a simple actions explorer.

The location of the RETURN also does not seem appropriate, so you can not get the following events.

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2018, 06:23 PM
Post: #5
RE: MOUSE command CLICK type
Hello Carlos,
i removed everything not needed to the execution of the project.
If you look at the code it should just detect a click and print it on the screen for 2 seconds when detected.

For a strange reason i don't know, the click is detected only when launching the program and clicking on the RUN soft menu.

Code:

EXPORT MAUZ_2()
BEGIN
 LOCAL T;
 WHILE ISKEYDOWN(30)≠1 DO
 T:=MOUSE();
    IF SIZE(T(1)) THEN
       IF T(1,5)==1 THEN
         TEXTOUT_P("CLICK!",G0,150,25);
         WAIT(2);   
         RECT_P(G0,150,20,190,40);
       END;
    END;
 END; 
END;

Why i am not able to detect a click in upper part of the screen? it seems the CLICK is detected only when clicking in the soft menu area...

My final goal, for other programs i would need are the management of:
- soft menu click (and that works)
- DRAG (a swipe) and that works
- click in the upper part of the screen (area different from the menu)...

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-26-2018, 07:34 PM
Post: #6
RE: MOUSE command CLICK type
MOUSE returns these types:
0: Click
1: Click in menu zone
2: Drag
3: Zoom
4: Rotate
7: Problematic type

I think that would look good:
Code:
EXPORT MAUZ_2()
BEGIN
 LOCAL T,U,V;
 RECT(#E0E0FF);
 DRAWMENU("Menu "+{1,2,3,4,5,6});
 WHILE ISKEYDOWN(4)≠1 DO
 WAIT(.005); //Very recomended
 T:=MOUSE();
   IF SIZE(T(1)) THEN
     U:=T(1,5);
     CASE
       IF U=0 THEN V:="CLICK: "+T(1,1)+","+T(1,2) END
       IF U=1 THEN V:="CLICK IN MENU "+IP(6*T(1,1)/320+1)END
       IF U=2 THEN V:="DRAG" END
       IF U=3 THEN V:="ZOOM" END
       IF U=4 THEN V:="ROTATE" END
         V:="UNDEFINED"
     END;
     TEXTOUT_P(V,G0,80,25,3);
     WAIT(.5);   
     RECT_P(80,20,320,45,#E0E0FF);
   END;
 END; 
END;

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2018, 07:52 PM
Post: #7
RE: MOUSE command CLICK type
Working with MOUSE, GETKEY and ISKEYDOWN is only recommended when requiring animations or similar, as in games, otherwise it is more optimal to work with WAIT (-1).

I have not yet written an article on interface creation, but I have published a short introduction at the end of a graphic article: Introduction to GUIs (Spanish).

If you want to explore WAIT(-1), try this code:
Code:
EXPORT WAIT_1_TEST
BEGIN
 RECT;
 LOCAL dat,ctr;

 REPEAT

  dat:=WAIT(−1);

  RECT;
  ctr:=ctr+1;
  TEXTOUT_P(dat,20,50,2); //Imprime lo retornado por WAIT(-1)
  TEXTOUT_P(ctr,20,65,2); //Un contador de repeticiones del bucle

  //wait(.5); //Activar para observar eventos intermedios.

 UNTIL 0;
END;

It is not necessary to convert the coordinates # 0:-16h to real data, you can compare them directly without problems. Using ISKEYDOWN or GETKEY can cause operating problems in WAIT (-1), however its use ends up being unnecessary.

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-27-2018, 04:22 PM (This post was last modified: 01-27-2018 04:24 PM by Giancarlo.)
Post: #8
RE: MOUSE command CLICK type
Hello Carlos,
Thank you very much for your help which is highly apreciated.
Using the MOUSE code above which is definitely more elegant than mine, there is never the possibility to detect mouse TYPES like 2, 3 or 4 since TYPE=0 being a mouse down, it is always triggered before turning into a DRAG, ROTATE.

Am i wrong? Are you able to detect mouse types different than 0 or 1?

For my application i would need to detect a CLICK (which is a selection of item in my application) and a DRAG (which is a LIST scroll in my application).

Thanks

Giancarlo



(01-26-2018 07:34 PM)Carlos295pz Wrote:  MOUSE returns these types:
0: Click
1: Click in menu zone
2: Drag
3: Zoom
4: Rotate
7: Problematic type

I think that would look good:
Code:
EXPORT MAUZ_2()
BEGIN
 LOCAL T,U,V;
 RECT(#E0E0FF);
 DRAWMENU("Menu "+{1,2,3,4,5,6});
 WHILE ISKEYDOWN(4)≠1 DO
 WAIT(.005); //Very recomended
 T:=MOUSE();
   IF SIZE(T(1)) THEN
     U:=T(1,5);
     CASE
       IF U=0 THEN V:="CLICK: "+T(1,1)+","+T(1,2) END
       IF U=1 THEN V:="CLICK IN MENU "+IP(6*T(1,1)/320+1)END
       IF U=2 THEN V:="DRAG" END
       IF U=3 THEN V:="ZOOM" END
       IF U=4 THEN V:="ROTATE" END
         V:="UNDEFINED"
     END;
     TEXTOUT_P(V,G0,80,25,3);
     WAIT(.5);   
     RECT_P(80,20,320,45,#E0E0FF);
   END;
 END; 
END;
Find all posts by this user
Quote this message in a reply
01-27-2018, 04:32 PM
Post: #9
RE: MOUSE command CLICK type
(01-27-2018 04:22 PM)Giancarlo Wrote:  Am i wrong? Are you able to detect mouse types different than 0 or 1?

For my application i would need to detect a CLICK (which is a selection of item in my application) and a DRAG (which is a LIST scroll in my application).

It is possible, if you need that the same area detects a click and a drag at the same time, you must create an algorithm that detects a finished click, otherwise you can separate each action according to the zone pressed, dividing the screen into small areas greatly facilitates its programming.

This is not a problem with all the events that WAIT(-1) returns, I recommend that you use it in replacement of the other action recognition commands

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
01-27-2018, 06:35 PM
Post: #10
RE: MOUSE command CLICK type
THank you very much.

Thanks for the link you provided yesterday. The amount of work you did is incredible on the graphical interfaces. I think that your interfaces are astonishing!

Really a good job. It’s in spanish but italian is not different from spanish so i was able to understand the content.

Thanks again

Giancarlo (from cappuccino state)
Find all posts by this user
Quote this message in a reply
01-29-2018, 07:09 AM
Post: #11
RE: MOUSE command CLICK type
Hello,

MOUSE (and ISKEYDOWN) vs WAIT(-1).

These 2 functions seems very similar, but do slightly different things.
WAIT is an EVENT function. Meaning that it returns events which are waitable on. Waitable event are great because, while waiting, the CPU is in low power mode. Events represent "instantaneous" data. This includes "key press" or "click".
Events are placed in an event queue and 'consumed' or removed one at a time.

MOUSE and ISKEYDOWN are much more continuous and return "state" data. current X/Y position for a mouse cursor for example.

Internally, state data is "interpreted" to generate events. However, the "interpreter" will add some meta data to the data to remember what is has decided in the past. Some of that info might be returned by MOUSE (I do not remember exactly), which might lead to confusion.

A mouse 'gesture' comes from interpreting the state data and should be aquired through a WAIT function.

This should help you decide what function to use.

For the specifics (from memory, so I might have some details wrong).

One trick that I have put in place is that "windows" (the calculator graphics is based on graphic windows) can give some hints to the gesture interpreter. Among other things, it can tell: 'I only accept clicks'. In this case, a mouse down imediately generates a click without having to wait for the mouse up. This is usefull as it gives the impression of faster UI. This is used in some windows like the menus. This is why when mousing in the menu area you can never get mouse move or similar events.

Hope this helps.
Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
01-29-2018, 08:16 PM
Post: #12
RE: MOUSE command CLICK type
Hello Cyrille,

Thank you very much for your comments. Now i better understand when to use one command than another.
I was writing a small program able to mimic the behaviour of the internal program showing the list of programs or list of note. Everything fine with the keys detection until i tried also to detect the click (to select one item of the list) and scrolls up and down to show the - hidden - part of the list scrolling it.
Are internal routines written in hppl or they were written in other language?

If Hppl how it was possible to manage the click event distinguished from the scroll? I know that CLICK and DRAG are different gestures, however it is not possible to detect which one was clicked and in case of DRAG in which direction?

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
01-30-2018, 06:13 AM
Post: #13
RE: MOUSE command CLICK type
Hello,

Click and Drag event are mutually exclusive.

A Down, with Moves that stay in the area of the down, followed by an UP will generate a Click.
A Down, with local moves and with no UP within the following 2/3 of a second will generate a long click.
A Down, with moves that go over a certain disctance will start generating drags until the UP event. Now, if the moves were fast enough, then extra moves (kinetik drags) will be generated to give a "momentum" effect.

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
02-24-2018, 10:08 PM
Post: #14
RE: MOUSE command CLICK type
Hello Cyrille,
thanks for the suggestion. it works very well.
This is the small code snippet i used to detect:
- keyboard press
- mouse move (up, down, left, right)
- click out of menu area
- click in the menu area and soft menu numer (1->6)

Code:

// Input handler for keyboard and touch screen
// by Giancarlo Cotrufo
// feb 24, 2018


EXPORT WEIT()
BEGIN
  RECT;
  LOCAL dat, ctr;
  LOCAL T0Y, T1Y, DY;
  LOCAL T0X, T1X, DX;
  REPEAT
   dat:=B→R(WAIT(-1)); // the dat variable store the keyboard/mouse event
   RECT;
   ctr:=ctr+1; // the ctr variable store the number of keyboard/mouse events
   TEXTOUT_P(dat,20,50,2);
   TEXTOUT_P(ctr,20,65,2);
   IF TYPE(dat)≠6 THEN TEXTOUT_P("KEY " + dat(),20,80,2); // phisical keyboard event
   ELSE // touch screen event
      IF dat(1)==0 THEN T0Y:=dat(3); T0X:=dat(2); END; // mouse down
      IF dat(1)==1 THEN T1Y:=dat(3); T1X:=dat(2); // mouse move on the touch screen
        CASE // detect direction of drag/swipe
          IF T1Y-T0Y>3 THEN TEXTOUT_P("DRAG ⇓  ",20,95,2); WAIT(.5); END;
          IF T1Y<T0Y THEN TEXTOUT_P("DRAG ⇑  ",20,95,2); WAIT(.5); END;
          IF T1X>T0X THEN TEXTOUT_P("DRAG ⇒ ",20,95,2); WAIT(.5); END;
          IF T1X<T0X THEN TEXTOUT_P("DRAG ⇐ ",20,95,2); WAIT(.5); END;
        DEFAULT
        END;
      END;
      IF dat(1)==3 THEN // normal click on the screen
         TEXTOUT_P("CLICK",20,80,2);
         IF dat(3)>219 THEN // detect the soft menu part of the screen
           TEXTOUT_P("CLICK MENU " + (1+IP(dat(2)*6/320)),20,80,2); //show which soft menu has been pressed
         END; // soft menu branch
      END // click branch
    END // keyboard/touch screen branch
  UNTIL 0; // loop
END;

Something interesting is that the mouse move on the touch screen creates 3 events for the WAIT command; thanks CARLOS for pointing out this feature.

Thanks Cyrille for explaining that the menu area for speed purpose just detect the click event. I can understand this feature however i could see a benefit in detecting a swipe (mouse move) in that soft menu area to mimic the PREV/NEXT command...

Thanks for all the explanation

Giancarlo
Find all posts by this user
Quote this message in a reply
02-26-2018, 06:00 AM
Post: #15
RE: MOUSE command CLICK type
Hello,

I understand what you mean. One day, I might have to do something along these lines.... Maybe implement variable size menus too!

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
03-04-2018, 11:08 AM
Post: #16
RE: MOUSE command CLICK type
Bonjour

Ce poste est très intéressant, personnellement en utilisant WAIT(-1) dans un programme pour détecté soit un click soit un glisser je me suis retrouvé confronté à un problème.
L'événement glisser a tendance à être détecté plusieurs fois, voici un peu l'architecture de mon programme:

Hello

This post is very interesting, personally using WAIT (-1) in a program to detect either a click or a drag I found myself facing a problem.
The drag event tends to be detected several times, here is a little architecture of my program:

Code:

For t FROM 1 TO 2 DO  // 2 tours autorisés  2 authorized tours
 af_tour  // routine d'affichage display routine
 REPEAT
   d:=ch_de  // appel routine de gestion écran avec WAIT(-1)  call screen management routine with WAIT (-1)
   CASE 
     if 0<d<6  THEN......
     if d==6 THEN .......
     if d==8 Then f:=1 END; // action glisser qui fait sortir de la boucle REPEAT drag action that gets out of the REPEAT loop
  UNTIL f
  .......
  .......
  .......
END;//for
 
ch_de
local ev,n
BEGIN
 while n==0 DO
  ev:=WAIT(-1);
  if TYPE(ev)==6 THEN
   if ev(1)==0 then x:=ev(2) end;
   if ev(1)==2 then  n:=IP((x-7)/40) end;
   if ev(1)==1 and ev(3)>32 then n:=8 end;
 END;
end;//while
 n;
END;
Le problème est que pour un seul glisser les 2 tours de boucle For t s'exécutent alors que 1 seul devrait le faire.
le click fonctionne très bien.
Le remède que j'ai trouvé insérer
Code:
WHILE MOUSE(4)<>-1 END;
avant
Code:
n:=8
dans ch_de qui je pense doit vider le buffer de WAIT(-1).

On voit d'ailleurs bien un temps de latence plus ou moins long selon l'amplitude du glisser.
Question peut-on vider le buffer de WAIT(-1) instantanément avec une instruction une fois nos événements acquis ?


The problem is that for a single drag the 2 rounds of loop For t execute while only 1 should do it.
the click works very well.
The remedy I found insert [code] WHILE MOUSE (4) <> - 1 END; [/ code] before [code] n: = 8 [/ code] in ch_de which I think must clear the buffer of WAIT ( -1).

We also see a latency time more or less long depending on the amplitude of the slide.
Question can we clear the buffer of WAIT (-1) instantly with an instruction once our events acquired?

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-04-2018, 11:46 AM
Post: #17
RE: MOUSE command CLICK type
I do not have problems with the drag of WAIT(-1), I think you should not use the WHILE function if you have a REPEAT, not is necessary 2 loops

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
03-04-2018, 05:11 PM
Post: #18
RE: MOUSE command CLICK type
(03-04-2018 11:46 AM)Carlos295pz Wrote:  I do not have problems with the drag of WAIT(-1), I think you should not use the WHILE function if you have a REPEAT, not is necessary 2 loops

Bonjour Carlos295p

Merci pour vôtre réponse, vous avez raison c'est logique la boucle while de la fonction ch_de peut être supprimée.
Je viens de le faire et cela fonctionne.
Malheureusement je suis toujours confronté au même problème, j'ai bien pensé à la vitesse d'exécution (je me suis déjà fait avoir) mais même en ralentissant avec un WAIT(n) le glisser
se répéte quand même.

D'ailleurs si je place un WAIT(-1) avant la boucle For t pour figer l'écran et que je fais un glisser
pour lancer la boucle celui-ci déclenche un événement glisser dans ch_de.

Hello Carlos295p

Thank you for your answer, you're right it's logical the while loop of function ch_de can be removed.
I just did it and it works.
Unfortunately I still face the same problem, I thought about the speed of execution (I'm already having) but even slowing down with a WAIT (n) drag
is repeated anyway.

By the way, if I put a WAIT (-1) before the For t loop to freeze the screen and I drag
to start the loop it triggers a drag event in ch_de.

Sorry for my english
Find all posts by this user
Quote this message in a reply
03-04-2018, 07:50 PM
Post: #19
RE: MOUSE command CLICK type
It is a little complicated to understand the situation of double displacement, could you make a small video showing it?

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
03-04-2018, 09:11 PM
Post: #20
RE: MOUSE command CLICK type
Hello,
The issue i had with my code in the previous post is that if you swipe in a direction which is not perfectly horizontal and vertical, the current code could detect a wrong direction.

If i had to adjust the code i should define a threshold to remove the possible wrong swipes.

Carlos, which app you use to record the videos?

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
Post Reply 




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