RPI Keyboard key code

Here is a piece of code I have used to translate. It doesn't do the whole job, but does what I need. If it is lower or upper, the shift key has it use a different translation table. If it is control, it is denoted and is used further down in some other code.

if(msg.payload == 42)  // Caps Shift key
    {
         if (msg.action == "down")
            context.set("Upper",1)
          else
            context.set("Upper",0)
    return null;
    }
if(msg.payload == 29)  // Control key
    {
         if (msg.action == "down")
            context.set("Control",1);
          else
            context.set("Control",0);
    return null;
    }


var translate      = "--1234567890-=  qwertyuiop[]  asdfghjkl;'   zxcvbnm,./"
var translateUcase = '--1234567890_+  QWERTYUIOP{}  ASDFGHJKL:"   ZXCVBNM<>?'
var key_in;
var cumulativeString = context.get("cumulativeString");
if (context.get("Upper")=== 0)
      key_in = translate.substring(msg.payload, msg.payload+1);
    else
      key_in = translateUcase.substring(msg.payload, msg.payload+1);
1 Like