# Keyboard matrix with multiple key

**URL:** <https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253>\
**Category:** Programming\
**Created:** [January 7, 2024, 8:58pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253 "2024-01-07T20:58:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 7, 2024, 8:58pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/1 "2024-01-07T20:58:42Z")

</div>

Good afternoon.

I need to make a keyboard with arduino leonardo and I am using matrix board.  
In the table I need a multiple key like for example shift+insert.  
does anyone know how i can do it

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 7, 2024, 10:04pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/2 "2024-01-07T22:04:15Z")

</div>

Welcome to the forum

Have you looked at the MultiKey example from the Keypad library ?

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 7, 2024, 10:20pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/3 "2024-01-07T22:20:43Z")

</div>

[quote="UKHeliBob, post:2, topic:1208253, full:true"]  
Welcome to the forum

Have you looked at the MultiKey example from the Keypad library ?  
[/quot

Thank you for your reply.  
I have seen it but it only mentions pressing multiple buttons.  
it does not mention them in a matrix

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 7, 2024, 10:25pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/4 "2024-01-07T22:25:14Z")

</div>

> [@dimtom](#):
>
> it does not mention them in a matrix

Really ?

Here are the first few lines of the sketch

```cpp
|| @description
|| | The latest version, 3.0, of the keypad library supports up to 10
|| | active keys all being pressed at the same time. This sketch is an
|| | example of how you can get multiple key presses from a keypad or
|| | keyboard.
|| #
*/

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the kpd
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the kpd

Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

```

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 7, 2024, 10:44pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/5 "2024-01-07T22:44:57Z")

</div>

maybe I didn't ask the question well.

could we have multiple clicks on one button??

diladi in the table of the example instead of having the position 1 I had.

{'KEY\_LEFT\_SHIFT+KEY\_INSERT ', '2', '3'},

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 7, 2024, 10:49pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/6 "2024-01-07T22:49:16Z")

</div>

You can only have a single character or byte value on a key but once you detect that key as having been pressed then it is up to you what you do in your sketch

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 7, 2024, 11:28pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/7 "2024-01-07T23:28:35Z")

</div>

are you telling me that I can make the matrix and as a hypothesis define that if 1 key is pressed, will be sent as an output KEY\_LEFT\_SHIFT +KEY\_INSERT?

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 6:12am UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/8 "2024-01-08T06:12:58Z")

</div>

I am telling you that you can decide what to do whatever you like on receipt of any key, even though they keypad sends only a single character.

Some pseudo code

```arduino
read key from keypad
if key equals 's'
  print "Mary had a little lamb"
else if key equals 't'
  turn on LED
else if key equals '#'
  send "rubbish" to the PC keyboard input
end if

```

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [January 8, 2024, 11:55am UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/9 "2024-01-08T11:55:53Z")

</div>

Hi @dimtom

welcome to the arduino-forum.

If you explain with more details and if you provide more information much better suggestions taylored to your project can be made.

You should provide a picture how your matrix-board looks like  
you should post a link to the datasheet of your matrix-board

You should describe to what kind of device you want to send "shift+insert" etc.  
You should describe over what kind of interface you want to send "shift+insert" etc.

You should give an overview about your project and describe what the final purpose of sending keystrokes like "shift+insert" is.

best regards Stefan

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 3:37pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/10 "2024-01-08T15:37:00Z")

</div>

Thank you very much, I will try it and get back to you

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 4:05pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/11 "2024-01-08T16:05:35Z")

</div>

As @StefanL38 has suggested, if you tell us what you want to do it will be easier to provide help

From the fact that you have used 'KEY\_LEFT\_SHIFT+KEY\_INSERT ' as your example it looks like you want to press a single key on the keypad and send keyboard commands to the PC. Is that what you are doing ?

By the way, 'KEY\_LEFT\_SHIFT+KEY\_INSERT ' is meaningless anyway, because a pair of single quotes can only be used with a single character, not a multi character string or String

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 4:29pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/12 "2024-01-08T16:29:33Z")

</div>

yes that is to i want. i need to press a single key on the keypad and sent keyboard commands to the pc double keys

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 4:39pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/13 "2024-01-08T16:39:16Z")

</div>

Using something like the code in post #8 you can do whatever you like on receipt of a single keypad button press but, of course, you need to turn it into real code

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 5:07pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/14 "2024-01-08T17:07:08Z")

</div>

when you can send me a complete code so that I can see the options with a 2x2 matrix and then I will do it in 7x7 that I want

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 5:40pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/15 "2024-01-08T17:40:35Z")

</div>

> [@dimtom](#):
>
> when you can send me a complete code

Never

It is time for you to write some code. Have you looked at the Keypad library examples ?

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 5:54pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/16 "2024-01-08T17:54:17Z")

</div>

ok.. i will see all the examples.

I will try to write the code.

and where I don't understand, correct me if you have time.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 5:56pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/17 "2024-01-08T17:56:15Z")

</div>

Start with HelloKeypad and adapt it

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 9:51pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/18 "2024-01-08T21:51:55Z")

</div>

because I can't figure out how to do it with matrix if I do it with button combination with

```arduino
void loop() {
  if while (digitalRead(2) == HIGH) && (digitalRead(3)==HIGH {

     delay(500);
   }
   delay(1000);
   Keyboard.press(ctrlKey);
   Keyboard.press('n');
   delay(100);
   Keyboard.releaseAll();
  
   delay(1000);
}

```

do you think it will work

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [January 8, 2024, 10:13pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/19 "2024-01-08T22:13:38Z")

</div>

Please make up your mind whether you want to press 2 buttons or 1 button in order to send multiple keypresses

Look again at the HelloKeypad example. Change

```cpp
  if (key)

```

to

```cpp
  if (key == '1')
{
  //put the code to be run when the user presses the '1' key here
}

```

---

<div class="post-metadata">

**Author:** ![dimtom](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dimtom/32/1126377_2.png) [@dimtom](https://forum.arduino.cc/u/dimtom)\
**Post date:** [January 8, 2024, 10:33pm UTC](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253/20 "2024-01-08T22:33:38Z")

</div>

i don't found that example

[Next page](https://forum.arduino.cc/t/keyboard-matrix-with-multiple-key/1208253.md?page=2)
