Post Reply 
Question about user mode key definitions.
09-03-2017, 10:53 PM
Post: #1
Question about user mode key definitions.
I call a function from a user mode key definition. When I clear the input line and put it in user mode and hit the key, the program is run.
However, if I put a number on the input line and hit the key, the old definition is run instead.
Why?
Note I'm redefining KS_Minus (the Base command) with a program that has a menu with hex, oct, bin, dec and exit as options. I want to have this program run when I hit shift-base and change the input line to the appropriate base. I have the menu part written, but the options (other than exit) don't do anything yet. So, the program runs if the input line is clear and I'm in user mode, but the original Base integer editor pops up instead if there is something on the input line.
Thx
-Donald
Find all posts by this user
Quote this message in a reply
09-04-2017, 05:57 PM (This post was last modified: 09-04-2017 06:11 PM by Stevetuc.)
Post: #2
RE: Question about user mode key definitions.
(09-03-2017 10:53 PM)webmasterpdx Wrote:  I call a function from a user mode key definition. When I clear the input line and put it in user mode and hit the key, the program is run.
However, if I put a number on the input line and hit the key, the old definition is run instead.
Why?
Note I'm redefining KS_Minus (the Base command) with a program that has a menu with hex, oct, bin, dec and exit as options. I want to have this program run when I hit shift-base and change the input line to the appropriate base. I have the menu part written, but the options (other than exit) don't do anything yet. So, the program runs if the input line is clear and I'm in user mode, but the original Base integer editor pops up instead if there is something on the input line.
Thx
-Donald

The user keys only seem to allow return as strings, so you could do:
KEY K_Minus()
BEGIN
"MBase()"
END

This would place MBase(). On the input line and <enter> to run.

Or maybe:

KEY K_Minus()
BEGIN
STRING(EVAL(MBase()))
END;

This will directly run MBase() evaluate the return and convert the returned argument to a string and place this ( without the quotes) on the input line. Press <enter> to place this on the stack or use any postfix operator as required to do math on result

Here is the MBase code I am using with this:

Code:


EXPORT MBase()
BEGIN
LOCAL men,m,m1,mx,my,s;
// initialize
WHILE MOUSE(1)≥0 DO END;
men:={"System","BIN","OCT","DEC","HEX","EXIT"};
PUTMENU(men); 
REPEAT // WAIT FOR A MOUSE CLICK
 m:=WAIT(−1);
UNTIL (m(1)==3 OR m(1)==7);
mx:=m(2); my:=m(3);
s:=GETMENU(mx,my,men);
RETURN s:=(SETBASE(Ans(1),s-1));
END;

(SETBASE(Ans(1),s-1)) takes input from the stack and converts to the base selected by the menu key given by s
Find all posts by this user
Quote this message in a reply
09-05-2017, 12:28 AM
Post: #3
RE: Question about user mode key definitions.
Did you actually try that out?
Shift-Base still seems to call the integer editor half the time....hard to figure out when it'll work.
Also, using your formulae, it keeps giving me a result of 1, even though Ans is 6....

???
Find all posts by this user
Quote this message in a reply
09-05-2017, 02:16 AM
Post: #4
RE: Question about user mode key definitions.
you can only run this in Cas mode, as it runs the integer editor in home mode.
however, it uses the stack from home mode, which is really weird....that's why I was getting 1...
...
Find all posts by this user
Quote this message in a reply
09-05-2017, 02:56 AM (This post was last modified: 09-05-2017 02:56 AM by Tim Wessman.)
Post: #5
RE: Question about user mode key definitions.
Just use Ans as a variable (no parens). That will be the home Ans last item.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
09-05-2017, 03:50 AM
Post: #6
RE: Question about user mode key definitions.
The problem is you can't really use KS_Minus as the key to override....for some reason.
If I use KA_3 (Alpha 3), it works....in home mode.
Find all posts by this user
Quote this message in a reply
09-05-2017, 04:23 AM
Post: #7
RE: Question about user mode key definitions.
(09-05-2017 12:28 AM)webmasterpdx Wrote:  Did you actually try that out?
Shift-Base still seems to call the integer editor half the time....hard to figure out when it'll work.
Also, using your formulae, it keeps giving me a result of 1, even though Ans is 6....

???

... Yes I did try it out!
The key definitions for K_Minus ( not KS_Minus) I used both work fine.
KS_Minus does have the problems you report.
Find all posts by this user
Quote this message in a reply
09-05-2017, 06:05 AM (This post was last modified: 09-05-2017 06:06 AM by leprechaun.)
Post: #8
RE: Question about user mode key definitions.
Quote:I want to have this program run when I hit shift-base and change the input line to the appropriate base.

I miss this possibility, too. There will be reasons why such little things are or had been ignored. These little feature improve the usability very much.
My approach is something like that. (SoftMenu() is a menu-laucher that returns the softkey id) The additional two ENTERs seem to be unavoidable. Is it possible to take input from the command line instead of the stack? so purge a number from input and save ENTERing it to the stack.

Code:
SymbBaseMenu()
BEGIN
  LOCAL base_key := Base+1;
  LOCAL btn:=SoftMenu({{"bin","oct","dec","hex","","2Real"},base_key});

  CASE
    IF btn==1 THEN   Base:=0;IFTE(Entry==2,"INT_BIN","INT_BIN(Ans)"); END;   //2D  : Entry==0
    IF btn==2 THEN   Base:=1;IFTE(Entry==2,"INT_OCT","INT_OCT(Ans)"); END;
    IF btn==3 THEN   Base:=2;IFTE(Entry==2,"INT_DEC","INT_DEC(Ans)"); END;
    IF btn==4 THEN   Base:=3;IFTE(Entry==2,"INT_HEX","INT_HEX(Ans)"); END;
   // IF btn=5 THEN RETURN " R→B(1)"; END;
    IF btn=6 THEN RETURN " B→R()"; END;
    DEFAULT "";
  END;

EXPORT INT_HEX(X)
BEGIN
  LOCAL str;
  CASE
    IF TYPE(X)==0 THEN R→B(X,32,4); END;
    IF TYPE(X)==1 THEN SETBASE(X,4); END; //Base is already set to 3 
    IF TYPE(X)==2 THEN X:=UCase(X);  str:="#"+X+"h"; R→B(expr(str)); END;
//    IF TYPE(X)==2 THEN  str:="#"+X+"h"; R→B(approx(str)); END;
 //   IF TYPE(X)==2 THEN str:="#"+X+"h";  INT_HEX( CAS(str)); END;
    DEFAULT "";
   END;
 // R→B(X,32,4);
END;

Prime and I are a love-hate. I dig out the prime occasionally but only for playing with it. The productivity level is frustratingly low for me.
Maybe that is because I work as a hardware designer with lowest level firmware on the software side. Script-languages and HPPPL seem to be too complicated for me.
Find all posts by this user
Quote this message in a reply
Post Reply 




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