Post Reply 
Can I access keys by their names
07-26-2016, 08:26 PM (This post was last modified: 07-26-2016 08:47 PM by StephenG1CMZ.)
Post: #5
RE: Can I access keys by their names
(07-25-2016 11:41 PM)Tim Wessman Wrote:  There is not any way to do this apart from numbers. The problem basically boils down to not wanting to create "nice names" for every possible variable option in the system. You'd probably be adding another 500 reserved words or so.

The reason it doesn't work is quite simple - 4 is not equal to a string.

What people normally do, is put in a comment or similar.

IF KK==4 THEN // K_Esc

When you said 4 is not equal to a string, I thought K ESC was a string.
But MSGBOX(STRING(K_Esc,))
Doesn't work - which could have been useful if you wanted to say "Press Escape to Escape" but refer to the key name consistently:
"Press "+K_Esc+" to Escape".

As an alternative to having 50 Exports, I was considering having one Export - effectively a list.
Whilst accessing a list would likely be less efficient than a constant, it minimises the number of exports, and also the list sequence associates a number with the key - which might be useful for the keys 0..9 0..F or A..Z.

Code:


LOCAL ZTypeString:=2;

 //HP KEYS: 0..50
 //INCOMPLETE
 ZKEYS:={
  "Apps","Symb", "Up",           "Help","Esc",
  "Home","Plot", "Left","Right", "View","CAS",
         "Num",  "Down",         "Menu"};

EXPORT  ZHPKey(XX)
 //RETURN ITEM (NUM OR KEYNAME)
 //SHIFTNAMES LETTERS DIGITS TBD
 BEGIN
  CASE
   IF TYPE(XX)==ZTypeString THEN 
    RETURN POS(ZKEYS,XX)-1;
   END;
   DEFAULT
    RETURN ZKEYS(XX+1);
  END;

 END;
 
 EXPORT Z_HP()
 BEGIN
  ZHPKey("Esc");ZHPKey(4):
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Can I access keys by their names - StephenG1CMZ - 07-26-2016 08:26 PM



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