Using Modifier Keys in "Keypad keypad = Keypad(makeKeymap(keys)" Array

I’m pretty much just getting started in this Arduino/Teensy world, and a modder friend of mine got me this far with a keypad mod. He wired the keypad to a teensy lc, and did all the mod work and software, so I’m a bit of a newb when it comes to programming this thing. All these keys seem to work great unless I try to throw modifier keys into the mix. Here’s the code that I have:

/** Keypad Bindings */
char keys[ROWS][COLS] = {
  {KEY_TAB,'q','w','e','r'},
  {MODIFIERKEY_SHIFT,'a','s','d','f'},
  {MODIFIERKEY_CTRL,'z','x','c',' '}
};

...

/**
 * Keypad globals
 */
byte rowPins[ROWS] = {16, 17, 18}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {19, 20, 21, 22, 23}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

...

void loop() {
  // Start - Keypad
  if (keypad.getKeys()) {
      for (int i = 0; i < LIST_MAX; i++) {
          if (keypad.key[i].stateChanged) {
              switch (keypad.key[i].kstate) {
                  case PRESSED:
                    Keyboard.press(keypad.key[i].kchar);
                    break;
                  case RELEASED:
                    Keyboard.release(keypad.key[i].kchar);
                    break;
              }
          }
      }
  }
  // End - Keypad

I’m looking for a solution that might allow me to include modifiers in my array. I’m thinking an integer array might be better suited to this situation, but I can’t seem to find a list of keys as integers in the key.h or keypad.h libraries. Thanks in advance for any help!

C4RP3N0CT3M:
… I’m thinking an integer array might be better suited to this situation … Thanks in advance for any help!

What is the actual issue? The code does not compile? The keypad does not respond?

Montmorency:
What is the actual issue? The code does not compile? The keypad does not respond?

It compiles, but the modifier keys don't respond. The "Tab" key sends a "+."

What are the values of KEY_TAB,MODIFIERKEY_SHIFT, and MODIFIERKEY_CTRL? Will those values fit in a signed 8 bit type?

What are the values of KEY_TAB,MODIFIERKEY_SHIFT, and MODIFIERKEY_CTRL? Will those values fit in a signed 8 bit type?

I'm not really sure how to answer that question. I'm a bit out of my depth. Those are from this list of keys Edit: (at the bottom). I was thinking of using these, but I'm not exactly sure if I can do that in a char array.

Edit 2: I loaded the above code with the hex values for the keys without apostrophes, and the modifier keys don't respond. If I put them as '0x80' (with apostrophes) I get the last letter/number.

and the modifier keys don't respond.

The range of values that you can store in a char (array) are from -128 to 127. The PJRC link shows the name of the keys, but not the values. The KeyboardModifiers link shows the names and the values. ALL of the modifier keys are outside of the range that can be stored in a char. THAT is why the value sent when you press one of the "modifier keys" is not the value that you expect.

You could change the array type to unsigned char, or byte. You might have to use a cast, or modify the library, to deal with a non-standard type (char, which is signed).

So I amended the array by adding some char values like so:

/** Keypad Bindings */
char tabKey = KEY_TAB;
char shiftKey = MODIFIERKEY_LEFT_SHIFT;
char ctrlKey = MODIFIERKEY_LEFT_CTRL;

char keys[ROWS][COLS] = {
  {tabKey,'q','w','e','r'},
  {shiftKey,'a','s','d','f'},
  {ctrlKey,'z','x','c',' '}
};

The problem is that the code below needs a syntax of Keyboard.press(ctrlKey), but I can’t seem to get the keypad.key{i}.kchar to equal ctrlKey using the above array.

void loop() {
  // Start - Keypad
  if (keypad.getKeys()) {
      for (int i = 0; i < LIST_MAX; i++) {
          if (keypad.key[i].stateChanged) {
              switch (keypad.key[i].kstate) {
                  case PRESSED:
                    Keyboard.press(keypad.key[i].kchar);
                    break;
                  case RELEASED:
                    Keyboard.release(keypad.key[i].kchar);
                    break;
              }
          }
      }
  }
  // End - Keypad
char tabKey = KEY_TAB;
char shiftKey = MODIFIERKEY_LEFT_SHIFT;
char ctrlKey = MODIFIERKEY_LEFT_CTRL;

A char can not hold a value greater than 127. All three of these values are greater than 127.

The problem is that the code below needs a syntax of Keyboard.press(ctrlKey), but I can't seem to get the keypad.key{i}.kchar to equal ctrlKey using the above array.

Well, gee, I wonder why.

Thanks for your help; I was unable to get it working.

C4RP3N0CT3M:
Thanks for your help; I was unable to get it working.

Um... Did you actually listen to what was suggested to you here?

As it has been stated repeatedly, again, again and again, your code has no chance of working as long as you are attempting to use char to store such values as MODIFIERKEY_LEFT_SHIFT.

You ignored all these suggestions and just continued your completely hopeless attempts to use char. No wonder you were unable to get it working.

Thank you for your help; unfortunately I was still unable to get it working utilizing the information provided in your last post. I'm clearly not knowledgeable enough to even ask for help. I apologize for my ignorance.

Change the type of the array from char to byte. Then, the values will fit.

That might cause other problems, but we can easily help you deal with them.