Can 74hc165 be used like keyboard

I want to send a computer keyboard key or sentence with Arduino leonardo and 74hc165? How it can be done?

What does the shift register have to do with it? The leonardo can send keypresses all by itself. Perhaps you should be a little more verbose with your question. One sentence is rarely enough to completely communicate the issue.

Delta_G:
What does the shift register have to do with it? The leonardo can send keypresses all by itself. Perhaps you should be a little more verbose with your question. One sentence is rarely enough to completely communicate the issue.

Yes, Leonardo is doing this. But I want to use fewer pins and get more output. I did this using the matrix button. I used 9 pins and got 20 outputs. (4x5 matrix) But I want more outputs with fewer pins. If it happens.
I’m using this code at now and it is work well done. I’m curious and I want to learning.

#include < Keyboard.h>

int cPins = {2, 3, 4, 5};
int cPinsNo = 4;
int rPins = {6, 7, 8, 9, 10};
int rPinsNo = 5;
int colPrev[4][5] = {0};
uint8_t buttonCodes[4][5] = {
{0x61, 0x65, 0x69, 0x76, 0x72},
{0x62, 0x66, 0x6A, 0x6E, 0x73},
{0x63, 0x67, 0x6B, 0x70, 0x74},
{0x64, 0x68, 0x6C, 0x71, 0x75},

};

void setup()
{
Serial.begin(115200);

for (int cPin = 0; cPin < cPinsNo; cPin++)
{
pinMode(cPins[cPin], OUTPUT);
digitalWrite(cPins[cPin], HIGH);
}

for (int rPin = 0; rPin < rPinsNo; rPin++)
{
pinMode(rPins[rPin], INPUT);
digitalWrite(rPins[rPin], HIGH);
}

}

void loop()
{

for (int cPin = 0; cPin < cPinsNo; cPin++)
{
digitalWrite(cPins[cPin], LOW);

for (int rPin = 0; rPin < rPinsNo; rPin++)
{

if (digitalRead(rPins[rPin]) == LOW)
{

if (colPrev[cPin][rPin] == 0)
{

Keyboard.press(buttonCodes[cPin][rPin]);
delay(150);
Keyboard.release(buttonCodes[cPin][rPin]);

colPrev[cPin][rPin] = 1;
}
}
else {

if (colPrev[cPin][rPin] == 1)
{

colPrev[cPin][rPin] = 0;
}
}
}
digitalWrite(cPins[cPin], HIGH);
}
}

AcarCnr: But I want more outputs with fewer pins.

The shift register you listed, 74HC165 is a parallel in / serial out shift register. It can give you more inputs but it isn't going to give more outputs. If you want more outputs then you need the 74HC595

It looks like OP is using the word "output" wrong, as he describes "20 outputs" when using a 4x5 switch matrix; those are inputs, not outputs.

I own both 74hc595 and 74hc165. Can it be done as a result.

AcarCnr: I own both 74hc595 and 74hc165. Can it be done as a result.

As you can see from the comments above, you're going to have to give a bit more detail about what exactly you want to do before anyone can answer that. We still can't tell if you want outputs or inputs. Why don't you take a few minutes and write out what this thing is supposed to do in the end. NOT how you think it would work, but what should it actually be able to do. What are you trying to create. If you come back with another one liner then I'll just put you on the ignore list. Please, if you want us to take the time to help you, you need to at least be willing to take the time to help us to do that.

The code posted points to inputs via wired matrix of buttons (no schematic, were diodes used? were hardware debounce caps used?) being read (or intended to) to trigger HID keyboard outputs on the USB.

Code to run input shift registers is not there.

OP might try Charlieplexing?

Delta_G: As you can see from the comments above, you're going to have to give a bit more detail about what exactly you want to do before anyone can answer that. We still can't tell if you want outputs or inputs. Why don't you take a few minutes and write out what this thing is supposed to do in the end. NOT how you think it would work, but what should it actually be able to do. What are you trying to create. If you come back with another one liner then I'll just put you on the ignore list. Please, if you want us to take the time to help you, you need to at least be willing to take the time to help us to do that.

+1 We need this to be part of this web site, right click a name, left click ignore all future threads. :)

.

It would be better if the keys are debounced in hardware whether in matrix or through a shift register, at least for the OP.

I want to do keyboard emulator with integrated and arduino. I made it in the form of a matrix and it works. I want to add more buttons, so I want to do it with integrated. For example; If I press matrix button 3x1, computer writes C. I want to do this with integrated. I am new to this platform and want to learn. And thank you for your answers.

Arduino Playground 74HC165 example.

It's not the best way but it might work.

It uses the SPI port pins but not the SPI library or the built-in port that lets you shovel bytes in and does all the bit sending in port hardware. Instead this example uses only the CPU.

It doesn't have any debounce code or hardware debounce. Bounce is what happens when contacts with voltage difference (like 5V and GND) are very close but not closed. Sparks will jump the gap when it gets small enough and fast code will "see" many on-off changes for a single press or release. Slow code won't catch them but that doesn't redeem slow code for what it is.

You can debounce a switch by wiring a 0.1uF capacitor across the contacts and get clean pin state changes that do not need any software debouncing. This includes buttons/keys wired to input shift registers.

You also really need to start looking things up. Does someone cut your food so you can eat? Internet search is like that.

AcarCnr: I did this using the matrix button. I used 9 pins and got 20 outputs. (4x5 matrix) But I want more outputs with fewer pins.

AcarCnr: I own both 74hc595 and 74hc165. Can it be done as a result.

Using a 595 and a 165, you should be able to read an 8x8 input matrix. (Or multiples of it using multiple chips chained. 8x16, 8x24, 16x16, etc..)

Use the same logic you did with your 4x5 matrix. But instead of just using digitalWrite() to put one row low, shift a byte into to 595 that has the right bit low. And instead of using digitalRead() on each input pin, read a byte from the 165 and then test each bit.

You will need pullup resistors on your inputs. And just like with your 4x5 matrix, you need to protect against shorts when pressing multiple buttons in the same column.

Thanks for the comments.

Jobi-Wan: Using a 595 and a 165, you should be able to read an 8x8 input matrix. (Or multiples of it using multiple chips chained. 8x16, 8x24, 16x16, etc..)

Use the same logic you did with your 4x5 matrix. But instead of just using digitalWrite() to put one row low, shift a byte into to 595 that has the right bit low. And instead of using digitalRead() on each input pin, read a byte from the 165 and then test each bit.

You will need pullup resistors on your inputs. And just like with your 4x5 matrix, you need to protect against shorts when pressing multiple buttons in the same column.

I also wanted to thank you. I will try to do what you say.