# Key Matrix

A key matrix is used when lots of keys are needed, or a keypad is being used.

A key matrix has the following schematic.

This particular key matrix has 12 keys laid out in a 4 row by 3 column grid. Only connections to each row and column need to be made to the Generic HID. Therefore, only 7 ports are used to enable 12 switches. The more rows and more columns, the bigger the savings. An 8x8 matrix will provide 64 buttons, while only using 16 ports.

Internally, the Generic HID will apply a voltage to one column at a time, then read the status of each row. If a key is pressed, the voltage on the row input pin will different.

Because of the shared nature of the key matrix, there is a restriction on how many keys can be pressed simultaneously. If two keys on different rows and different columns are pressed, no key will be shown as pressed. The key matrix is best used when it makes sense that only one key is pressed at the same time. If a button is required to be on all the time (toggle switch), or just a button that needs to be used in combination with others, a regular button should be used.

## Properties

### Name

Components can be given an optional name. This is seen in the Test tab. Not all applications support the name. Hidcomp/hidconfig supports names.

### UsageMin

HID usage of the first key. Other keys are number consecutively. See Usages for more information.

### Rows

The number of rows in the matrix. Note that the display of the key matrix isn't updated when the number of rows is changed. There is also a visual limit of 8 rows. If you need more than 8 rows, you'll need to define the device via an .mcd file.

### Columns

The number of columns in the matrix. Note that the display of the key matrix isn't updated when the number of columns is changed. There is also a visual limit of 8 columns. If you need more than 8 columns, you'll need to define the device via an .mcd file

### Key Names

The optional user friendly name given to each key. This property is edited in a separate dialog.

### Debounce (ms)

Waits for the mechanical switch stop bouncing before registering a switch closure. Enter the time to wait in milliseconds. See Mechanical Switches for more information.

### Current

Defines the amount of electrical current used by the LED in mA. This is used to estimate the USB power draw. See the section on Power for more information. A Key matrix uses virtual no current so this field can be set to 0.