title: Automatically press a specific keyboard key in MATLAB
body: <p>Is there a way to get MATLAB to automatically press a specific keyboard key?
  My internet connection disconnects without no reason. I want to make a script in MATLAB which check the internet connection status periodically and if the connection is disconnected the program will run the connection automatically.
  I want to write a script in MATLAB which automatically run a connection (first picture). Then program should automatically press Enter key (“Connect” button in the first picture).  After this the second window will appear(second picture). In the second window if I click “connect” button, then the connection will connect to the internet. 
  Here is my script:</p>
  
  <pre><code>function [] = AutoConn()
  tic ;
  
  cTime = 2 ;
  k = 0 ;
  A = 0 ;
  while(1)
      nTime = toc ;
      tic ;
      C = isnett ;
      if C == 1
          A = 1 ;
      else
          A = 0 ;
          system('C:\...\Connection.pbk');
        {....}
  
      end
      clc;
      k = k+1;
      k
      A
      pause(cTime) ;
  end
  
  
  function flag = isnett()
  % This function returns a 1 if basic internet connectivity
  % is present and returns a zero if no internet connectivity
  % is detected.
  
  % define the URL for US Naval Observatory Time page
  url =java.net.URL('http://tycho.usno.navy.mil/cgi-bin/timer.pl');
  
  % read the URL
  try
      link = openStream(url);
      parse = java.io.InputStreamReader(link);
      snip = java.io.BufferedReader(parse);
  catch
      flag = 0;
      return
  end
  if ~isempty(snip)
      flag = 1;
  else
      flag = 0;
  end
  </code></pre>
  
  <p>First Picture:
                 <a href="http://i.stack.imgur.com/OEy6W.png" rel="nofollow">http://i.stack.imgur.com/OEy6W.png</a></p>
  
  <p>Second Picture:
                 <a href="http://i.stack.imgur.com/TPlEN.png" rel="nofollow">http://i.stack.imgur.com/TPlEN.png</a></p>