// constants won't change. They're not really used // only here as a reference const int upPin = 12; const int rightPin = 7; const int downPin = 8; const int leftPin = 4; //The important thing here is the order between pins and keyCodes match //For example, pin 12 is up, 218 corresponds to Up key on the keyboard //http://arduino.cc/en/Reference/KeyboardModifiers int pins[] = {12, 7, 8, 4}; int keyCodes[] = {218, 215, 217, 216 }; int prevState[] = {0, 0, 0, 0}; int buttonState = 0; int i = 0; void setup() { pinMode(12, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); pinMode(4, INPUT); Keyboard.begin(); // Serial.begin(9600); } void loop(){ for (i = 0; i < 4; i++) { buttonState = digitalRead(pins[i]); //just released if (buttonState == HIGH) { Keyboard.press(keyCodes[i]); } else { Keyboard.release(keyCodes[i]); } prevState[i] = buttonState; } delay(100); }