 /*
-Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
-For more information see: github.com/seytonic/malduino
+  ==============================================================
+    Copyright (c) 2017 Seytonic, Spacehuhn (Licensed under MIT)
+      For more information see: github.com/seytonic/malduino
+  ==============================================================
 */
 
 #include <SPI.h>
 #include <SD.h>
 #include "Keyboard.h"
 
-//#define debug true // <-- uncomment to turn serial output on
+#define debug true // <-- uncomment to turn serial output on
 #define CSpin 4 //Chip-Select of the SD-Card reader
 #define ledPin 3
 #define blinkInterval 50

  #endif
  
  if(e - s < 2) Keyboard.press(buf[s]);
  else if(equals(s,e,"ENTER",5)) Keyboard.press(KEY_RETURN);
  else if(equals(s,e,"GUI",3) || equals(s,e,"WINDOWS",5)) Keyboard.press(KEY_LEFT_GUI);
  else if(equals(s,e,"SHIFT",5)) Keyboard.press(KEY_LEFT_SHIFT);
  else if(equals(s,e,"ALT",3)  ||equals(s,e,"ALT_LEFT",8) ||equals(s,e,"ALTLEFT",7)) Keyboard.press(KEY_LEFT_ALT);
  else if(equals(s,e,"ALT_RIGHT",9) ||equals(s,e,"ALTRIGHT",8)) Keyboard.press(KEY_RIGHT_ALT);
  else if(equals(s,e,"CTRL",4) || equals(s,e,"CONTROL",7)) Keyboard.press(KEY_LEFT_CTRL);
  else if(equals(s,e,"CAPSLOCK",8)) Keyboard.press(KEY_CAPS_LOCK);
  else if(equals(s,e,"DELETE",6)) Keyboard.press(KEY_DELETE);
  else if(equals(s,e,"END",3)) Keyboard.press(KEY_END);
  else if(equals(s,e,"ESC",3) || equals(s,e,"ESCAPE",6)) Keyboard.press(KEY_ESC);
  else if(equals(s,e,"HOME",4)) Keyboard.press(KEY_HOME);
  else if(equals(s,e,"INSERT",6)) Keyboard.press(KEY_INSERT);
  else if(equals(s,e,"PAGEUP",6)) Keyboard.press(KEY_PAGE_UP);
  else if(equals(s,e,"PAGEDOWN",8)) Keyboard.press(KEY_PAGE_DOWN);
  else if(equals(s,e,"SPACE",5)) Keyboard.press(' ');
  else if(equals(s,e,"TAB",3)) Keyboard.press(KEY_TAB);
  else if(equals(s,e,"BACKSPACE",9)) Keyboard.press(KEY_BACKSPACE);
  
  else if(equals(s,e,"UP",2) || equals(s,e,"UPARROW",7)) Keyboard.press(KEY_UP_ARROW);
  else if(equals(s,e,"DOWN",4) || equals(s,e,"DOWNARROW",9)) Keyboard.press(KEY_DOWN_ARROW);
  else if(equals(s,e,"LEFT",4) || equals(s,e,"LEFTARROW",9)) Keyboard.press(KEY_LEFT_ARROW);
  else if(equals(s,e,"RIGHT",5) || equals(s,e,"RIGHTARROW",10)) Keyboard.press(KEY_RIGHT_ARROW);
  
  else if(equals(s,e,"PRINTSCREEN",11)) Keyboard.press(PRINTSCREEN);

  else if(equals(s,e,"F1",2)) Keyboard.press(KEY_F1);
  else if(equals(s,e,"F2",2)) Keyboard.press(KEY_F2);
  else if(equals(s,e,"F3",2)) Keyboard.press(KEY_F3);
  else if(equals(s,e,"F4",2)) Keyboard.press(KEY_F4);
  else if(equals(s,e,"F5",2)) Keyboard.press(KEY_F5);
  else if(equals(s,e,"F6",2)) Keyboard.press(KEY_F6);
  else if(equals(s,e,"F7",2)) Keyboard.press(KEY_F7);
  else if(equals(s,e,"F8",2)) Keyboard.press(KEY_F8);
  else if(equals(s,e,"F9",2)) Keyboard.press(KEY_F9);
  else if(equals(s,e,"F10",3)) Keyboard.press(KEY_F10);
  else if(equals(s,e,"F11",3)) Keyboard.press(KEY_F11);
  else if(equals(s,e,"F12",3)) Keyboard.press(KEY_F12);

  else if(equals(s,e,"NUM_0",5)) KeyboardWrite(KEYPAD_0);
  else if(equals(s,e,"NUM_1",5)) KeyboardWrite(KEYPAD_1);
  else if(equals(s,e,"NUM_2",5)) KeyboardWrite(KEYPAD_2);
  else if(equals(s,e,"NUM_3",5)) KeyboardWrite(KEYPAD_3);
  else if(equals(s,e,"NUM_4",5)) KeyboardWrite(KEYPAD_4);
  else if(equals(s,e,"NUM_5",5)) KeyboardWrite(KEYPAD_5);
  else if(equals(s,e,"NUM_6",5)) KeyboardWrite(KEYPAD_6);
  else if(equals(s,e,"NUM_7",5)) KeyboardWrite(KEYPAD_7);
  else if(equals(s,e,"NUM_8",5)) KeyboardWrite(KEYPAD_8);
  else if(equals(s,e,"NUM_9",5)) KeyboardWrite(KEYPAD_9);
  else if(equals(s,e,"NUM_ASTERIX",11)) KeyboardWrite(KEYPAD_ASTERIX);
  else if(equals(s,e,"NUM_ENTER",9)) KeyboardWrite(KEYPAD_ENTER);
  else if(equals(s,e,"NUM_Minus",9)) KeyboardWrite(KEYPAD_MINUS);
  else if(equals(s,e,"NUM_PERIOD",10)) KeyboardWrite(KEYPAD_PERIOD);
  else if(equals(s,e,"NUM_PLUS",8)) KeyboardWrite(KEYPAD_PLUS);

  #ifdef debug 
      else Serial.println("failed");
  #endif
  
  /* not implemented
  else if(equals(s,e,"APP",3)) Keyboard.press();
  else if(equals(s,e,"MENU",4)) Keyboard.press();
  else if(equals(s,e,"BREAK",5) || equals(s,e,"PAUSE",5)) Keyboard.press();
  else if(equals(s,e,"NUMLOCK",7)) Keyboard.press();
  else if(equals(s,e,"SCROLLLOCK",10)) Keyboard.press();
  */
}



  if(space == -1) runCommand(0,bufSize);
  else{
    if(equalsBuffer(0,space,"DEFAULTDELAY") || equalsBuffer(0,space,"DEFAULT_DELAY")) defaultDelay = getInt(buf,space);
    else if(equalsBuffer(0,space,"DEFAULTCHARDELAY") || equalsBuffer(0,space,"DEFAULT_CHAR_DELAY")) defaultCharDelay = getInt(buf,space);
    else if(equalsBuffer(0,space,"DELAY")) delay(getInt(buf,space));
    else if(equalsBuffer(0,space,"STRING")){
      for(int i=space+1;i<bufSize;i++) KeyboardWrite(buf[i]);
    }
    else if(equalsBuffer(0,space,"REM") || equalsBuffer(0,space,"REPEAT")){}
    else{
      runCommand(0,space);
      while(space >= 0 && space < bufSize){
