Latency of a computer keyboard? (Not a midi controller)

Discuss music production with Ableton Live.
Post Reply
kaffein
Posts: 1195
Joined: Fri Nov 03, 2006 2:52 pm
Location: Houston, Texas
Contact:

Latency of a computer keyboard? (Not a midi controller)

Post by kaffein » Sun Sep 16, 2007 3:26 pm

I'm curious if anyone knows the avg latency of computer/pc keyboards?

It kinda feels like it's greater than 7ms to me, but I guess you have to add in the time it takes to fully depress the keys... So excluding that what would the interface latency be?

noisetonepause
Posts: 4938
Joined: Sat Dec 28, 2002 3:38 pm
Location: Sticks and stones

Post by noisetonepause » Sun Sep 16, 2007 4:37 pm

Whatever latency you're feeling is from the audio interface (or possibly the soft synth), not the keyboard.

How much latency from when you press a key till the letter shows up on the screen?
Suit #1: I mean, have you got any insight as to why a bright boy like this would jeopardize the lives of millions?
Suit #2: No, sir, he says he does this sort of thing for fun.

kaffein
Posts: 1195
Joined: Fri Nov 03, 2006 2:52 pm
Location: Houston, Texas
Contact:

Post by kaffein » Mon Sep 17, 2007 5:36 am

I'm talking about the latency of a Computer Keyboards, USB and/or PS/2... Not a midi controller keyboard. :|

Timur
Posts: 2203
Joined: Mon Sep 17, 2007 8:55 am

Post by Timur » Mon Sep 17, 2007 11:14 am

It depends on two things the keyboard itself and the interface being used. Unfortunately I do not know how keyboards are connected in notebooks (PC or MAC), but I suspect they're connected via USB nowadays. From here on it's becoming quite technical and some informations may be incorrect. Feel free to correct me where you find errors.

1. Interface

Actually there are two ways of getting data from an interface: Interrupt and Polling. Interrupt means that the interface (controller chip) that the device is attached to sends an interrupt to the CPU whenever it receives data from the interface, when no data is received no interrupt is send. Polling means that the CPU/Software checks the interface/controller itself on a regular or irregular basis, when it finds data it will be fetched, when not then the check was rather useless. Keyboard controllers on Windows PCs use interrupt mode, I guess it's the same on Apple computers, but I found no informations on that. Whatever, even in interrupt mode the interrupted CPU must still fetch the data actively, so either way the CPU must be free to do so or interrupt other tasks to do it (like streaming audio from your audio interface).

PS/2: PS/2 connected keyboard on a PC send their data to the input buffer (!) of the keyboard controller (which is on the mainboard) and then an interrupt 1 to the CPU when you press a key. The CPU/OS has to fetch the data from that input buffer then and the keyboard controller will tell the keyboard that it can send again. Interrupt 1 is a very high priority interrupt (right after 0: the system timer), but still the data has to be fetched. Whenever you hear your computer beep instead of doing something when you press a key that means that the keyboard input buffer is full but the CPU does not fetch its data. But due to the high priority interrupt you will usually still be able to use the keyboard even when the system is under heavy load stress.

At least for the PS/2 mouse the standard rate is 100 Hz (100 times per second), I couldn't find any info on the keyboard rate, but most likely it's the same. This corresponds to a maximum latency of 10 ms, but usually it will be lower. Also the input buffer usually can hold more than one key, that means when you press three keys for a chord more or less at once they will be fetched all at once with virtually no latency (they are still send one after another instead even when you press them at once). Windows XP allows the PS/2 rate of the mouse to be upto 200 Hz, but there is no setting for the keyboard. Also this is a maximum setting which can drop significantly under heavy load (the PS/2 mouse has a lower priority interrupt). Also increasing the rate will increase CPU load measurably.

Since a PS/2 keyboard uses a higher priority interrupt than your audio-device (especially if it's a Firewire or USB solution) it may interfere with very low buffer/latency settings on the audio device. But since so very little data is transfered for keyboard actions it's quite unlikely.

USB: The USB protocol has four different transfer modes, one being the interrupt mode. The interrupt mode is used for devices like keyboard and mouse (did someone finally define the plural of computer mouse in english?) that send little data but need a guaranteed rate. All devices connected to the USB share the very same interrupt and data line though (actually all USB1.1 devices share one interrupt and all USB2.0 share another, keyboards are USB1.1), so several devices connected to the USB may conflict with each other for total bus supremacy. :wink: Since the USB interrupt is usually of lower priority you will notice that keyboard and mouse can respons sluggish whenever the system is under heavy load stress.

The standard USB rate on a Windows computer is 125 Hz and I suspect it to be the same on Apple computers, but unfortunately found no informations on that. 125 Hz correspond to a maximum latency of 8 ms, but usually it will be lower. Actually the USB standard allows a rate of upto 1000 Hz which corresponds to a maximum latency of only 1 ms. There are hacks for Windows XP that allow you to set the USB rate to 125/250/500/1000 Hz, but the more you increase the rate the more your CPU load will increase as well.

2. Keyboard

All keyboards are not the same! Their internal build differs in how they react to key pressure and how many keys you can press at one time (and even which areas of the keyboard allow more keys to be pressed at once). So called Gaming keyboards are actually often best to use for making music. They usually allow a high number of keys to be pressed at one time and react quickly to key pressure (meaning you only have to press the key slightly to invoke a key on command whereas bad keyboard require you to press the key all the way down).

How many keys you can press at once on the very same keyboard can depend on two factors, the area of the keys you press and wether you're using PS/2 or USB. Area means that oftentimes current keyboards allow you to press more keys around the keys W,A,S,D because these are mostly used for gaming. Many keyboards allow more keys to be pressed/transmitted at once when using USB as opposed to PS/2 (like my very own keyboard does), so for playing chords it may be good to use USB.

Beside this the main difference is wether you use a wired keyboard or a wireless and how wireless is implemented. For example: eventhough Logitech wireless gear transmits the wireless data at a rate of 125 Hz from the keyboard to the receiver and thus should show no latency/lag when compared to a wired USB keyboard it indeed does behave "different". I had a Cordless Desktop LX 700. Whenever I pressed several keys at one they are always transmitted one after another with an easily perceiveable lag. So instead of playing chords with all notes starting together they started one after another, or when you pressed two keys to play a kick and hihat sound together the hithat would play a short instance after the kick. It's well possible that other wireless keyboards behave different though.

PS about the maximum latency mentioned above:

Whenever I wrote maximum latency I mean a latency ranging from 0 to that maximum value. That is because you will like never press a key just the very moment that the interface has just been sending data, but most of the time you will press it somewhat in between. So let's say you use an USB keyboard which transmits it's data at a rate of 125 Hz. That means that the CPU will fetch the data of the input buffer every 8 ms. If you pressed a key 1 ms before the input buffer is flushed the next time then your latency will be 1 ms, if you pressed the key 7 ms before the buffer is flushed then it will be 7 ms. So actually latency depends alot on when you press a key, with a maximum at 8 ms, an average of appr. 4.5 ms and a minimum of 0 ms. When the rate of the interface is increased to 1000 Hz then the data from the input buffer is fetched every 1 ms, so your maximum latency will decrease as well as your average latency, but the minimum is the same. The size of the input buffer cannot be changed for keyboards as far as I know (whereas it can be changed for a PS/2 mouse under some OS).

zappen
Posts: 345
Joined: Sat Jul 16, 2005 1:42 am

Post by zappen » Mon Sep 17, 2007 2:02 pm

well explained

Timur
Posts: 2203
Joined: Mon Sep 17, 2007 8:55 am

Post by Timur » Mon Sep 17, 2007 10:20 pm

Thanks for the flowers! :) Although I found lots of grammatical errors in my explanation. Hehe 8)

Herne
Posts: 139
Joined: Sat Oct 21, 2006 11:45 am

Post by Herne » Mon Sep 17, 2007 11:14 pm

Standard polling rate for XP and earlier PS2 polling is 60Hz [about 16ms], there's lots of freeware for setting your polling rate right up to 1000Hz [1ms] such as PS2Rate.
USB standard polling rate is 125Hz [8ms]. Some performance mice [Logitech, Razer etc. will set this up to 1000Hz]. Most of this software is designed for maximum mouse response, and not keyboard though, high dpi and poll rate is great for FPS gaming.

To answer your original question USB will be faster, and more responsive, but probably really hard to tell in real world terms, unless you're a CounterStrike champion :-)

If you want top performance get a Razer gaming keyboard, thay have a massive buffer, and allow multiple simultaneous presses, with no problems.
Live 6.10 | Vista Ultimate | Reason 3 |
Athlon 64 X2 6400 | 4GB DDR2 8000 |
Axiom 61 | BCR2000 | PadKONTROL |

Timur
Posts: 2203
Joined: Mon Sep 17, 2007 8:55 am

Post by Timur » Tue Sep 18, 2007 7:22 am

Yep, I think you're right, 60 Hz it was for PS/2 mouse, but wasn't it 100 Hz in Windows XP? I could put my mouse on the PS/2 port to check, but I have been crawling under my table for days to set up my new homerecording stuff and my knees hurt now. 8)

Herne is a town that I have been living in for about 30 years until my lady dragged me to her hometown Oberhausen. ;)

Tarekith
Posts: 19082
Joined: Fri Jan 07, 2005 11:46 pm
Contact:

Post by Tarekith » Tue Sep 18, 2007 11:44 am

Thanks guys, very informative!

kaffein
Posts: 1195
Joined: Fri Nov 03, 2006 2:52 pm
Location: Houston, Texas
Contact:

Post by kaffein » Wed Sep 19, 2007 1:54 am

Good info in this thread!

I'm actually a gamer so I'm really picky with my mice and have found my preference, but my keyboard is an ongoing battle... I'm still searching for my perfect baby.

Timur
Posts: 2203
Joined: Mon Sep 17, 2007 8:55 am

Post by Timur » Fri Sep 21, 2007 12:03 pm

I just had a look at a PC running a PS/2 mouse with Windows XP and the default setting in device-manager is 100 Hz. ;)

Post Reply