HP Forums

Full Version: User-Key
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
maybe I dont't understand the concept at all - maybe you can explain to me what happens:

I put the following code into a program:

KEY K_Mul()
BEGIN
RETURN 42;
END;

After pressing pressing Shift Help * in home-environment I get
1 as answer - but I expected 42

I also have a function
EXPORT ENG()
BEGIN
RETURN 42;
END;

which answers 42 as I expected.

Hm, this really puzzles me... I'm not understanding what I'm doing...

Thank you
Dirk.
Use Shift+Help to enable the user keyboards. Twice to held it active (for K_Mul)
Try with:

KEY K_Mul()
BEGIN
RETURN "42";
END;

See page 561 of the English manual. A user Key program is expected to return a string.
If you return only a numerical (integer) value, then the system will apply the key corresponding to that value. The 1 returned is from carrying out button 42, which is the 1 key.
(11-16-2015 03:14 PM)Han Wrote: [ -> ]If you return only a numerical (integer) value, then the system will apply the key corresponding to that value. The 1 returned is from carrying out button 42, which is the 1 key.

Oh! good to know
Thank you very much,
well, this is an interesting feature which did not become clear for me when reading the german translation of the user guide.
So the behaviour of RETURN-statement is different when called in a "normal" function from the behaviour when called in a "KEY"-Function.
Why would I want to "apply a key" as a result instead of returning a value?

Would it be possible, to return "42" (i.e. put it into the entry-line") and "apply" the Enter-Key afterwards to have it as a "normal" result avaliable on screen and in the Ans-variable. This would save the user from pressing Enter.

Thank you very much.
Dirk.
Hello,

Nope, sorry, you can only perform one operation at this time...
At one point, I tried to make it more versatile but did not succeed..

Cyrille
Thank you very much for your answer.
I find it a bit irritating, that the return statement not always behaves the same.
however, maybe, it is possible to introduce a possibility to push something onto the "home stack" or have an "exit" statement behaving like I would the "return" expect to behave... or "fix" the "return" and have an additional "exit".

This could help to develop very convenient sequences of "user-key macros".

A further idea might be the addition of some sort of cursor-position-parameter, which would allow to position the cursor back, for example into the brackets just printed by the function.

Greetings
Dirk.
Reference URL's