Arduino Keyboard and Mouse Control Code

This example illustrates the use of the Mouse and keyboard libraries together. Five momentary switches act as directional buttons for your cursor. When a button is pressed, the cursor on your screen will move, and a keypress will be sent to the computer. Once you have the Leonardo programmed and wired up, open up your favorite text editor to see the results.

Arduino Keyboard and Mouse Control

NB: When you use these libraries, the Arduino takes over your computer’s keyboard and mouse!

Software Required
  • Any text editor

Circuit

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic

Arduino Keyboard and Mouse Control schematic

Code

/*
KeyboardAndMouseControl

Controls the mouse from five pushbuttons on an Arduino Leonardo or Micro.

Hardware:
* 5 pushbuttons attached to D2, D3, D4, D5, D6

The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.

WARNING:  When you use the Mouse.move() command, the Arduino takes
over your mouse!  Make sure you have control before you use the mouse commands.

created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe

this code is in the public domain

*/

[box color=”#985D00″ bg=”#FFF8CB” font=”verdana” fontsize=”14 ” radius=”20 ” border=”#985D12″ float=”right” head=”Major Components in Project” headbg=”#FFEB70″ headcolor=”#985D00″]

Hardware Required

  • Arduino Leonardo or Arduino Due board
  • breadboard
  • Five pushbuttons
  • Five 10-kiloohm resistors

[/box]

For more detail: Arduino Keyboard and Mouse Control Code


About The Author

Ibrar Ayyub

I am an experienced technical writer with a Master's degree in computer science from BZU Multan University. I have written for various industries, mainly home automation and engineering. My writing style is clear and simple, and I am skilled in using infographics and diagrams. I am a great researcher and am able to present information in a well-organized and logical manner.

Follow Us:
LinkedinTwitter
Scroll to Top