# RPI Keyboard key code

**URL:** <https://discourse.nodered.org/t/rpi-keyboard-key-code/20063>\
**Category:** General\
**Created:** [8 January 2020 15:38 UTC](https://discourse.nodered.org/t/rpi-keyboard-key-code/20063 "2020-01-08T15:38:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetwater](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sweetwater](https://discourse.nodered.org/u/sweetwater)\
**Post date:** [8 January 2020 15:38 UTC](https://discourse.nodered.org/t/rpi-keyboard-key-code/20063/1 "2020-01-08T15:38:59Z")

</div>

Using the standard RPI Keyboard node to detect Keyboard entries.

Using a standard USB keyboard ( usa layout). When pressing:  
a : code = 30  
b: code= 48  
1: code 2  
f1: code = 59

Does anyone know the code lookup table?  
This does seem to match up with the ACII table.

 ![rpi_keyboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b89bba617b1f53c4293482f0932d72ff32c9cce1.png)

---

<div class="post-metadata">

**Author:** ![adamswm92](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@adamswm92](https://discourse.nodered.org/u/adamswm92)\
**Post date:** [10 January 2020 08:35 UTC](https://discourse.nodered.org/t/rpi-keyboard-key-code/20063/2 "2020-01-10T08:35:07Z")

</div>

If you don't mind me asking, how were you able to use the rpi keyboard node, anytime I drop it in my flow it is says "stopped" in red letters under it

---

<div class="post-metadata">

**Author:** ![Kenmazing](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@Kenmazing](https://discourse.nodered.org/u/Kenmazing)\
**Post date:** [3 February 2020 15:17 UTC](https://discourse.nodered.org/t/rpi-keyboard-key-code/20063/3 "2020-02-03T15:17:14Z")

</div>

It seems to correspond to keyboard layout. So A=30, S = 31, Q=16, W=17, etc. It doesn't correspond to ASCII or USB, so I am a bit puzzled myself.

To get it to start, deploy it with a keyboard attached.

---

<div class="post-metadata">

**Author:** ![Kenmazing](https://avatars.discourse-cdn.com/v4/letter/k/e68b1a/32.png) [@Kenmazing](https://discourse.nodered.org/u/Kenmazing)\
**Post date:** [7 February 2020 16:23 UTC](https://discourse.nodered.org/t/rpi-keyboard-key-code/20063/4 "2020-02-07T16:23:37Z")

</div>

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);
```
