Kudos for the very interesting question. Unfortunately, I can't seem to find a global event handler for all key presses other than overriding ProcessCmdKey on the main form per this article. Only issue with this method is that the arguments passed into the event handler delegate don't define what control is creating the event :(
So, my only thought is that you need to assign your event handler to every single control in the application. I've written some code that should help show you how to do this. I'm not sure what the adverse effects may be of assigning a KeyPress event handler to every control on your page though, but it's the only feasible solution I see.
Code:
private void Form1_Load(object sender, EventArgs e)
{
AssignHandler(this);
}
protected void HandleKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter && (sender != this.textBoxToIgnore || sender ! this.gridViewToIgnore))
{
PlaySound(); // your error sound function
e.Handled = true;
}
}
public void AssignHandler(Control c)
{
c.KeyPress += new KeyPressEventHandler(HandleKeyPress);
foreach (Control child in c.Controls)
{
AssignHandler(child);
}
}