Reduce delay between keyboard keys sent on ps2keyboard library

Hello everybody.

I'm using the ps2keyboard library and I'm having a problem related to the rate that the keys are being sent. For my project necessities it is too slow.

Is that any way that I can reduce the delay between each key sent to the computer by the ps2 keyboard connected to the arduino, like, when you press and hold the key 'a' on your keyboard you notice a delay between each letter on your screen, if I could lower this delay on the library would help me a lot.

thanks!!

Please post a link to the library you are using.

sorry aarg, I'm new to the forum, here is the library:

Thanks. Isn't the repetition rate set by the particular keyboard that you have plugged in, not the program itself? It seems to be just a "port reader" that passes on whatever is received from the keyboard.

aarg, on windows you can set this repetition rate regardless of which keyboard you are using, so, my guess was that the answer was on the code of the library

Does the library actually support auto repetition?

I guess so, because it behaves like a common keyboard. like, when you press and hold a key it show once on the screen, and after a second start repeating itself a little bit faster, like any keyboard.

Yes, but that doesn't point to the source of the repetition. It could be anywhere in the chain. By the way, I have the source code up and I don't see anything there that looks repetition related. But I haven't spent more than 15 minutes on it.

What code are you testing it with? What is your hardware? How is it interconnected?

Have you tried increasing the rate in Windows settings, as you mentioned it's possible to do?

the code is:

#include <PS2Keyboard.h>

const int DataPin = 8;
const int IRQpin =  3;
PS2Keyboard keyboard;

void setup() {
  delay(1000);
  keyboard.begin(DataPin, IRQpin);
  Serial.begin(9600);
  pinMode(10, OUTPUT);
}

void loop() {
  if (keyboard.available()) {
    digitalWrite(10, HIGH);
    // read the next key
    char c = keyboard.read();
    Serial.print(c);
  }
  else {
    digitalWrite(10, LOW);
  }
}

my hardware: I'm using an arduino pro-micro, its connected to the keyboard just like specified on the lib documentation

I tried increasing the rate, but it does not has effect on the arduino.

That is the OS (Windows) doing auto-repeat. The keyboard just sends KeyDown and KeyUp events. It's the OS that times the auto-repeat. Check the keyboard section of the control panel. There may be a slider for setting repeat delay and repeat rate. There is on Mac OS X.

Are you sure john? If so, do you know a library that get these events? instead of simulating a real keyboard?

The code is open source. Have a look for yourself. This library does get those events, so you're asking for different handling on the PC end... not feasible.

You need to ask a more open question... it has to be about what you are actually using this feature for, what you are actually doing. Not how to do it using your fixed, preconceived idea of how it must be done. Therefore you need to tell us a lot more details and with a lot more scope, about your goal.

Also, if you need to send auto repeats, can you not just send multiple key presses at whatever frequency you desire? A key press is sent on your command!

But again, you probably won't get any good advice here unless you explain what you need this feature for.

Sorry aarg, I'll try to be more precise:

I need to control a robot's movement using a ps2 keyboard.

the robot it's consists of an arduino pro micro and 4 servo motors.

What I need is: know when a key on the ps2 keyboard is pressed and when it's released, and which key was pressed or released.

As an example: When I press 'a' on the keyboard, I would turn on a led (led 1), when I press 's' I would turn on another led (led 2), when I release the key 'a' the led 1 would turn off and when I release the key 's' the led 2 would turn off.

thank you for your help and patience.

That is definitely an incomplete answer - there is no mention at all about why you need auto-repeat which seems to be your main interest.

Edit - I thought the functionality you list, is already present in the library, but maybe no. It looks like it discards the key up/down information in the process of determining a key press (i.e. full keystroke).

Hello Aarg, I would like to thank you for your help, but I solved this problem.

The keyboard has a membrane with rows and cols (similar to those matrix keyboards for arduino) and the rows and columns of this membrane goes into a little PCB that read the keystrokes, process them and send it to the ps2 port.

So I opened my keyboard, mapped every row and column from the little PCB and I connected the arduino directly into the membrane.

Now I'm using the keyboard just like I would use the matrix keyboard. And that solves my problem.

Here is some pictures:
The PCB from the keyboard and the custom board that I have made (to map only numbers and letters I needed to read only 8 rows and 8 cols, 16 pins total)

The result of the mapping of the rows and cols from the PCB:

and the final result, when I connected the custom board to the keyboard and connected it to the arduino (it's messy I know)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.