Post new question
Question
Reply
 
Tutor
Posts: 20
Member Since: ‎10-16-2008
Message 1 of 5 (531 Views)

Can a user key definition only return a string?

Product Name: HP Prime
Operating System: Other

The Prime's manual (2nd ed., pages 571ff) teaches us that we can reassign keys in the user keyboard. The only example, however, is one where the corresponding "program" returns a string.

 

I, however, would like to execute my own program when a certain user key is pressed and I thought this will work:

 

EXPORT Next(N)
BEGIN
  IF odd(N) THEN
    RETURN 3*N+1;
  ELSE
    RETURN N/2;
  END;
END;

KEY K_Xttn(M)
BEGIN
  Next(M);
END;

However, back in the Home screen (I'm in UPN mode most of the time) when I put a number on the stack and then press Shift-Help (User) xttn-Key I just get an X in the input line. 😒 

 

So is there no way I can repeatedly execute my program by just pressing one key in the user keyboard (in persistent user mode)? This was something I very often did on my HP48 back then ... I, too, loved that I could press the top row keys for that and saw on the display what they did. Unfortunately, the Prime's menu keys on the display are just six all black rounded filled ractangles and totally useless. Or can I fill those with functionality?

Reply
0 Kudos
Teacher
Posts: 101
Member Since: ‎05-30-2013
Message 2 of 5 (501 Views)

Re: Can a user key definition only return a string?

Hello,

 

if a user key returns a string, that string is handled as a text which is entered in the calculator.

if a user key returns a number, it is assume that this is a key code, which is executed instead of the original key.

all else is ignored and the original key is executed.

If you want no further actions taken than your program, return the number of a useless key (such as 41 for shift if I am not mistaken).

 

Cyrille

I am an HP Employee
Tutor
Posts: 20
Member Since: ‎10-16-2008
Message 3 of 5 (487 Views)

Re: Can a user key definition only return a string?

Thanks, Cyrille.

However, returning some integer that's not a keycode is not an option here because my program returns the result of a calculation and I want this to be on the stack – so that I can press the User-key again to take the result as input to my program.

So what was no problem on an HP48 is not possible on the Prime, right? 😒 

It would be SO cool if the useless, empty black key labels on the screen could be assigned to functions/programs like it was possible with the HP28/48/49/50 series ...

Best,

Stefan.

Grad Student
Posts: 200
Member Since: ‎09-23-2016
Message 4 of 5 (462 Views)

Re: Can a user key definition only return a string?

[ Edited ]

It is not such a bad idea to let a user key return a string, because when the string is the name of a program, and we press Enter next, the program is executed!

 

So by pressing 1 key we will not get things done, but by pressing a key, and Enter next, we will.

 

Then our program is:

 

EXPORT Next(N)
BEGIN
  IF odd(N) THEN
    RETURN 3*N+1;
  ELSE
    RETURN N/2;
  END;
END;

KEY K_Xttn()
BEGIN
  RETURN "Next";
END;

 

 

Highlighted
Grad Student
Posts: 200
Member Since: ‎09-23-2016
Message 5 of 5 (452 Views)

Re: Can a user key definition only return a string?

We can also write a program which allows us to tap an arbitrary key in order to achieve the same thing.

 

For this purpose we use the PRINT command and insert it into an endless loop.

 

To end the loop and the program press Shift – On.

 

Before starting the program assign a value to N.

 

 

NEXT();              //declaration of programs
MYPROG();

EXPORT NEXT()
BEGIN
  PRINT();             //clears the screen
  REPEAT               //start of loop
    PRINT(N);
    WAIT;           //waits for pressing key
    PRINT();        //clears the screen
    N:=MYPROG(N);    
  UNTIL 0;
END;

MYPROG(N)
BEGIN
 IF odd(N) THEN
   RETURN 3*N+1;
 ELSE
   RETURN N/2;
 END;
END;


 

† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation