user4066: I wanted to use either Arduino Mega or Uno as a form of an interface between me and the computer. I want to apply it to the following scenario; if I press a button on a circuit board I want it to trigger an action on my computer, like scroll down.
How can I achieve this? How would the code look like and what programs would I need to translate from Arduino to Windows?

user-1: You can do that easily with a few of the Arduino boards that have built-in USB communications support.
You find that feature on Leonardo, Micro, Esplora and Due boards. You also find that on some Arduino compatible boards like the Adafruit Flora.
Simply plug the Arduino USB port to your computer and the Arduino will behave like a keyboard. Then you can program your sketch to perform what you want with your buttons. Check the Arduino  mouse and keyboard library.

user113: Arduino Yun, Leonardo, Esplora and Due have  the ability to appear as a native Mouse and/or Keyboard to a connected computer by use of the Mouse and Keyboard libraries.
Here's an example of how you would use SWITCH3 on the Esplora to active PAGE UP on your keyboard.
if (!Esplora.readButton(SWITCH_3)) {
  Keyboard.press(KEY_PAGE_UP)
  delay(100);
  Keyboard.releaseAll();
  }

Here's an example of using the Esplora to control the Keyboard and Mouse to control the Flight Simulator option of Google Earth.
If you want to use the Uno it's more difficult but it can be done by sending data from the Uno to a Python program running on the PC. The Python program uses the pywin library to control windows.
Here's a fully worked out Instructable on how to do it.

user612: For the sake of completeness, on the more traditional boards where the USB interface is not implemented from the main "sketch" processor, there are three other potential possibilities:

Use the (USB) serial data interface, and have software on the host computer which accepts commands over that.  Obviously, the downside is requiring installation of something on the host system - installation which may require admin privileges or even disabling code signing requirements in some cases (especially if it is to inject the data into the host operating system as if it came from a keyaboard)
On boards such as the Uno and comparable-generation Mega which use a secondary ATmega "u" series part as a USB-serial converter, this chip can be reprogrammed to act instead as a keyboard.  That could make loading sketches tricky - though it might be possible to come up with a dual-mode firmware that could switch roles under control of an external hardware or software signal.
The main ATmega "sketch" processor can generally implement a "not quite compliant, but workable" approximation of a low-speed USB interface in software on arbitrary I/O pins with some external matching/protection componenets.  A USB keyboard is a common demo application of that.


4066: <p>I wanted to use either Arduino Mega or Uno as a form of an interface between me and the computer. I want to apply it to the following scenario; if I press a button on a circuit board I want it to trigger an action on my computer, like scroll down.</p>

<p>How can I achieve this? How would the code look like and what programs would I need to translate from Arduino to Windows?</p>
 -1: <p>You can do that easily with a few of the Arduino boards that have built-in USB communications support.</p>

<p>You find that feature on Leonardo, Micro, Esplora and Due boards. You also find that on some Arduino compatible boards like the Adafruit Flora.</p>

<p>Simply plug the Arduino USB port to your computer and the Arduino will behave like a keyboard. Then you can program your sketch to perform what you want with your buttons. Check the Arduino  <a href="http://arduino.cc/en/Reference/MouseKeyboard#.Uxt6yuddVTY" rel="nofollow">mouse and keyboard library</a>.</p>
 113: <p>Arduino Yun, Leonardo, Esplora and Due have  the ability to appear as a native Mouse and/or Keyboard to a connected computer by use of the <a href="http://arduino.cc/en/Reference/MouseKeyboard#.Uxt-kIWzBzw" rel="nofollow">Mouse and Keyboard libraries</a>.</p>

<p>Here's an example of how you would use SWITCH3 on the Esplora to active PAGE UP on your keyboard.</p>

<pre><code>if (!Esplora.readButton(SWITCH_3)) {
  Keyboard.press(KEY_PAGE_UP)
  delay(100);
  Keyboard.releaseAll();
  }
</code></pre>

<p><a href="http://www.instructables.com/id/Arduino-Esplora-Flight-Simulator/" rel="nofollow">Here's an example</a> of using the Esplora to control the Keyboard and Mouse to control the Flight Simulator option of Google Earth.</p>

<p>If you want to use the Uno it's more difficult but it can be done by sending data from the Uno to a Python program running on the PC. The Python program uses the pywin library to control windows.</p>

<p><a href="http://www.instructables.com/id/Flight-Simulator-with-Arduino-and-Python/" rel="nofollow">Here's a fully worked out Instructable</a> on how to do it.</p>
 612: <p>For the sake of completeness, on the more traditional boards where the USB interface is not implemented from the main "sketch" processor, there are three other potential possibilities:</p>

<ul>
<li><p>Use the (USB) serial data interface, and have software on the host computer which accepts commands over that.  Obviously, the downside is requiring installation of something on the host system - installation which may require admin privileges or even disabling code signing requirements in some cases (especially if it is to inject the data into the host operating system as if it came from a keyaboard)</p></li>
<li><p>On boards such as the Uno and comparable-generation Mega which use a secondary ATmega "u" series part as a USB-serial converter, this chip can be reprogrammed to act instead as a keyboard.  That could make loading sketches tricky - though it might be possible to come up with a dual-mode firmware that could switch roles under control of an external hardware or software signal.</p></li>
<li><p>The main ATmega "sketch" processor can generally implement a "not quite compliant, but workable" <em>approximation</em> of a low-speed USB interface <em>in software</em> on arbitrary I/O pins with some external matching/protection componenets.  A USB keyboard is a common demo application of that.</p></li>
</ul>
