Post Reply 
How to use MOUSE
02-24-2020, 10:46 PM
Post: #1
How to use MOUSE
Hi all,
For user input on the screen there is the command MOUSE. According to the description, this command provides two lists with the following content: {#x, #y, #originalx, #originaly, #type}. To see what the actual output of this command looks like, I have created a small program, see the code below. The output is as follows: {{#125:-16h;#EF:-16h;#125:-16h;#EF:-16h;#1:16h};{}}. With repeated program execution, a number of values change, probably depending on where you press the screen. If I compare the description with the output, I notice that each of the fields in the list corresponds to 2 values. I would like to know which of these values I must use to be able to operate a program from the screen. I cannot find a good description of this command in the manual, as well as an example in which this is used. I would like to have some more documentation of this command, as well as some examples in which this is used. Can someone help me with that? Thanks in advance! Sincerely, Karel.

Code:

EXPORT TEST()
BEGIN
L1:=MOUSE();
END;

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-25-2020, 12:05 AM
Post: #2
RE: How to use MOUSE
In my experience the WAIT(-1) command is more reliable and preferred. Returns a real for key press (or -1 after 1 minute timeout), or a list for mouse events. You can use WAIT(-1) inside a REPEAT clause until you have the type of result you want. While paused, the command puts the calculator into a lower power state as well, IIRC. Here's an example:

Code:
REPEAT
  IFERR MK_in:=WAIT(-1); THEN // IFERR to catch ON key press which generate error
    MK_in:=4;
    FlushKeysMouse(); // separate command to wait until results from ISKEYDOWN and MOUSE are empty, eliminates unintentional events
  END;
UNTIL TYPE(MK_in)==0 OR IFTE(SIZE(MK_in)>1,MK_in(1)==3,0); // looking for key press or mouse click event only

What is your intended use case?
Visit this user's website Find all posts by this user
Quote this message in a reply
02-25-2020, 03:07 AM
Post: #3
RE: How to use MOUSE
Dear Mr. Wall,
Thank you very much for your response! I don't have a specific application at the moment, but I do work a lot with menu keys in my programs, and in the future also with screen touches. I also often work with menu keys on the HP-50g, so it won't be any different on the HP Prime. The Prime reports that there is an error in line 2 in your program. Maybe you can check your program for errors. I will experiment with this program as soon as the errors are removed. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
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
02-25-2020, 06:46 AM
Post: #5
RE: How to use MOUSE
Hello,

MOUSE is for "dynamic" UI detection. It shows/represent the real time mouse information.

In comparison, WAIT(-1) returns mouse/keyboard information from the event queue, which means that if you are slow in getting the data, you can get old data.

The use case for these 2 functions is different. WAIT is useful for a UI type program with buttons and the like where you DO want to respond to user interaction, even if it is "late". MOUSE (and ISKEYDOWN) return the realtime status and is best suited for realtime applications like games and the like where you need to act immediately on user actions.

MOUSE returns what is basically the internal state of the mouse buffers. The current position, where the pointer was first detected down and a state indicator telling you what the system has detected so far (new, completed, drag, stretch, rotate, long click)... But if your program is too slow, it can miss transient events such as new, or long click...

I hope that 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
02-26-2020, 09:39 PM
Post: #6
RE: How to use MOUSE
Dear Mr. Wall,
Thank you for this new program. I tested it and it works. I will study it carefully in the coming period, and then make a program myself with the techniques that are included in this program. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-26-2020, 10:37 PM
Post: #7
RE: How to use MOUSE
(02-25-2020 06:46 AM)cyrille de brébisson Wrote:  Hello,

MOUSE is for "dynamic" UI detection. It shows/represent the real time mouse information.

In comparison, WAIT(-1) returns mouse/keyboard information from the event queue, which means that if you are slow in getting the data, you can get old data.

The use case for these 2 functions is different. WAIT is useful for a UI type program with buttons and the like where you DO want to respond to user interaction, even if it is "late". MOUSE (and ISKEYDOWN) return the realtime status and is best suited for realtime applications like games and the like where you need to act immediately on user actions.

MOUSE returns what is basically the internal state of the mouse buffers. The current position, where the pointer was first detected down and a state indicator telling you what the system has detected so far (new, completed, drag, stretch, rotate, long click)... But if your program is too slow, it can miss transient events such as new, or long click...

I hope that this helps.

Cyrille
Dear sir de Brébisson,
It is all a bit too complicated for me at the moment. I especially need a command that does not matter how long it takes before the user gives a response. This is important because the programs I want to make may not stop prematurely, or get other weird cures. At the moment I think that command is MOUSE, although it is not yet clear to me how to use this command. I will study the sample programs that I have received. Still, I hope to get more documentation or sample programs elsewhere or from someone else. In any case, I want to thank you very much for your contribution. Sincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
02-28-2020, 06:18 PM
Post: #8
RE: How to use MOUSE
Hello,
in this old thread we analized the different behaviour of the two touch detecting commands WAIT and MOUSE.

i found this thread very interesting. i hope it helps in your research.

https://www.hpmuseum.org/forum/thread-10...ight=mouse

thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
02-29-2020, 02:27 AM
Post: #9
RE: How to use MOUSE
(02-28-2020 06:18 PM)Giancarlo Wrote:  Hello,
in this old thread we analized the different behaviour of the two touch detecting commands WAIT and MOUSE.

i found this thread very interesting. i hope it helps in your research.

https://www.hpmuseum.org/forum/thread-10...ight=mouse

thanks

Giancarlo

Dear Giancarlo,
Thank you very much for your response. I will have to study it carefully, and that will take time. Cincerely, Karel.

I use HP-16C, WP-34S emulator, HP-35s, HP-48GX, HP-50g, and HP Prime G2.
Find all posts by this user
Quote this message in a reply
Post Reply 




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