need help with keypad matric and keyboard shorcuts

hi, firs off all im new to programming :smiley:

made matrix keyboard 6x6
tested with arduino game controler skech so pins working and ok

byte rowPins[NUMROWS] = {4,3,2,5,6,7};
byte colPins[NUMCOLS] = {12,11,10,9,13};

now i want to asing every button on matrix as keyboard button like if i pres first button on matrix i get same like i pressed ctr+v on keyboard

anyone can suggest ant samples?

You can use a struct to define which keys need to be pressed when you press a key on the matrix. The below struct allows for a normal key and two modifiers (e.g. ctrl, alt).

// include keyboard functionality
#include <Keyboard.h>

// macro to calculate number of elements in an array
#define NUMELEMENTS(x) (sizeof(x) / sizeof(x[0]))

// struct for key and modifiers
struct KEY
  const uint8_t key;
  const uint8_t mod1;
  const uint8_t mod2;

In the above, I've also included a macro to count the number of elements in an array.

Next you can declare an array of those structs, one for each key of the keypad

KEY keys[] =
  {KEY_ESC, KEY_LEFT_CTRL, 0},  // invoke start menu
  {'v', KEY_LEFT_CTRL, 0},      // paste

Next you can write a function to send the keys; the below function takes a number as the index in the keys array.

  send keys (e.g. <n>, <ctrl><v>, <ctrl><esc>) to PC
    index indicating which key combination to send
void pressKey(uint8_t index)
  // safety precaution; connect A5 to GND to enable HID functionality
  if (digitalRead(A5) == HIGH)
    Serial.println("HID functionality disabled");
  // check if a valid index was passed
  if(index >= NUMELEMENTS(keys))
    Serial.println("Invalid index");

  if (keys[index].mod1 != 0)
  if (keys[index].mod2 != 0)

The code first checks if HID functionality is enabled and next checks (using the earlier defined macro) if it's a valid index. If both conditions are satisfied, it will press the required keys (0 for a modifier indicates that you will not send a modifier) and after a little while it will release the keys.

Next you can write your setup() and loop(). I've not implemented a keypad, I'll leave that to you; if you have a simple keypad with numbers 0..9, you can simply subtract '0' from the key that you read from the keypad and use that as the index.

void setup()
  while (!Serial);

  // A5 used to enable HID functionality
  pinMode(A5, INPUT_PULLUP);

void loop()

The above code will send every second opening and closing the start menu on a Windows system if you have wired A5 to ground.

You need a board with native USB (e.g. Leonardo) or you need to hack an Uno or Mega (possibly needs some modificcations of the code, no idea). Tested on a Leonardo.

thanks for replay but the code is too complicate for my to finish it. :confused: :confused:
can you finish code and i can edit it to my needs.

what i what to reach is, each of matrix 6x6 key to do keyboards buttons for example


and so one... shortcuts do not mater i will change them later