Windows works with only one message queue, so only a message with a key will be processed at any given time. You can do all the key events in a short period of time (0.5 seconds for instace), save all the pressed keys in a list or queue, and then play all the sounds according to the keys asynchronously (using streams). I have never done this before, but I think it should work. Hope helps ...
EDIT
Ok, let's see: first a list of where to save the keys
List<Key> _keys = new List<Key>();
Then start the timer to check the pressed keys for the time interval:
var t = new System.Timers.Timer(500);
Then the t_Elapsed method (note that if you are in WPF you must use DispatcherTimer , this timer is on System.Timers )
void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { if (_keys.Count > 0) {
And then the on down down method:
void OnKeyDownMethod(object sender, KeyPressedEventArgs e) //not sure this is the name of the EventArgs class { _keys.Add(e.Key); //need to check }
You can try this, hopefully it will be useful.
source share