title: JQuery timeout function
body: <p>I am trying to use jquery/javascript to do the following but am having trouble finding any information about how to get it done.</p>
  
  <p>I want to create a function that when called, will wait for 2 seconds for a response from the user (a keypress for example). If a response is collected anytime within the 2 seconds, event A is executed while if there is no keypress withing 2 seconds, event B is executed.</p>
  
  <pre><code>function waitForInput
  {
  if(response within 2 second timeout?) event a executed
  else if (timed out) event b executed
  }
  </code></pre>