 
         case KEY_MUHENKAN:
             keyboardState.muhenkanPressed = false;
-            releaseModifier(MODIFIER_LEFT_SHIFT);
+            releaseLeftShift();
 
             return;
 
         case KEY_SPACE:
             keyboardState.spacePressed = false;
-            releaseModifier(MODIFIER_LEFT_SHIFT);
+            releaseLeftShift();
             if (keyboardState.noEventBetweenSpaceEvents) {
-                pressKey(KEY_SPACE);
-                releaseKey(KEY_SPACE);
+                Keyboard.press(KEY_SPACE);
+                Keyboard.release(KEY_SPACE);
             }
 
             return;
 
         default:
-            releaseKey(keyMappings[MAPPING_HENKAN][key]);
-            releaseKey(keyMappings[MAPPING_NEUTRAL][key]);
-    }
-}
-
-void dudrackModifiersChange(uint8_t modifiers) {
-    changeModifiers(modifiers);
-}
-
-void stgKeyDown(uint8_t key) {
+            Keyboard.release(keyMappings[MAPPING_HENKAN][key]);
+            Keyboard.release(keyMappings[MAPPING_NEUTRAL][key]);
+    }
+}
+
+void stgKeyDown(KeyboardKeycode key) {
     switch (key) {
         case STICK_DOWN_KEY:
             gamepadState.downPressed = true;
-            Joystick.setYAxis(STICK_DOWN);
-
-            return;
+            Gamepad.yAxis(STICK_DOWN);
+
+            break;
 
         case STICK_UP_KEY:
             gamepadState.upPressed = true;
-            Joystick.setYAxis(STICK_UP);
-
-            return;
+            Gamepad.yAxis(STICK_UP);
+
+            break;
 
         case STICK_LEFT_KEY:
             gamepadState.leftPressed = true;
-            Joystick.setXAxis(STICK_LEFT);
-
-            return;
+            Gamepad.xAxis(STICK_LEFT);
+
+            break;
 
         case STICK_RIGHT_KEY:
             gamepadState.rightPressed = true;
-            Joystick.setXAxis(STICK_RIGHT);
-
-            return;
-
-        case BUTTON_0_KEY:
-            Joystick.pressButton(0);
-
-            return;
+            Gamepad.xAxis(STICK_RIGHT);
+
+            break;
+
+        case BUTTON_1_KEY:
+            Gamepad.press(1);
+
+            break;
 
         case BUTTON_2_KEY:
-            Joystick.pressButton(2);
-
-            return;
+            Gamepad.press(2);
+
+            break;
+
+        case BUTTON_3_KEY:
+            Gamepad.press(3);
+
+            break;
+
+        case BUTTON_4_KEY:
+            Gamepad.press(4);
+
+            break;
 
         case BUTTON_5_KEY:
-            Joystick.pressButton(5);
-
-            return;
+            Gamepad.press(5);
+
+            break;
 
         case BUTTON_6_KEY:
-            Joystick.pressButton(6);
-
-            return;
-    }
-}
-
-void stgKeyUp(uint8_t key) {
+            Gamepad.press(6);
+
+            break;
+
+        case BUTTON_7_KEY:
+            Gamepad.press(7);
+
+            break;
+    }
+
+    Gamepad.write();
+}
+
+void stgKeyUp(KeyboardKeycode key) {
     switch (key) {
         case STICK_DOWN_KEY:
             gamepadState.downPressed = false;
-            Joystick.setYAxis(gamepadState.upPressed ? STICK_UP : STICK_NEUTRAL);
-
-            return;
+            Gamepad.yAxis(gamepadState.upPressed ? STICK_UP : STICK_NEUTRAL);
+
+            break;
 
         case STICK_UP_KEY:
             gamepadState.upPressed = false;
-            Joystick.setYAxis(gamepadState.downPressed ? STICK_DOWN : STICK_NEUTRAL);
-
-            return;
+            Gamepad.yAxis(gamepadState.downPressed ? STICK_DOWN : STICK_NEUTRAL);
+
+            break;
 
         case STICK_LEFT_KEY:
             gamepadState.leftPressed = false;
-            Joystick.setXAxis(gamepadState.rightPressed ? STICK_RIGHT : STICK_NEUTRAL);
-
-            return;
+            Gamepad.xAxis(gamepadState.rightPressed ? STICK_RIGHT : STICK_NEUTRAL);
+
+            break;
 
         case STICK_RIGHT_KEY:
             gamepadState.rightPressed = false;
-            Joystick.setXAxis(gamepadState.leftPressed ? STICK_LEFT : STICK_NEUTRAL);
-
-            return;
-
-        case BUTTON_0_KEY:
-            Joystick.releaseButton(0);
-
-            return;
+            Gamepad.xAxis(gamepadState.leftPressed ? STICK_LEFT : STICK_NEUTRAL);
+
+            break;
+
+        case BUTTON_1_KEY:
+            Gamepad.release(1);
+
+            break;
 
         case BUTTON_2_KEY:
-            Joystick.releaseButton(2);
-
-            return;
+            Gamepad.release(2);
+
+            break;
+
+        case BUTTON_3_KEY:
+            Gamepad.release(3);
+
+            break;
+
+        case BUTTON_4_KEY:
+            Gamepad.release(4);
+
+            break;
 
         case BUTTON_5_KEY:
-            Joystick.releaseButton(5);
-
-            return;
+            Gamepad.release(5);
+
+            break;
 
         case BUTTON_6_KEY:
-            Joystick.releaseButton(6);
-
-            return;
-    }
-}
-
-void stgModifiersChange(uint8_t modifiers) {
-    MODIFIERKEYS mod = *((MODIFIERKEYS*)&modifiers);
-
-    if (mod.BUTTON_1_MODIFIER) {
-        Joystick.pressButton(1);
-    } else {
-        Joystick.releaseButton(1);
-    }
-
-    if (mod.BUTTON_3_MODIFIER) {
-        Joystick.pressButton(3);
-    } else {
-        Joystick.releaseButton(3);
-    }
-
-    if (mod.BUTTON_4_MODIFIER) {
-        Joystick.pressButton(4);
-    } else {
-        Joystick.releaseButton(4);
-    }
+            Gamepad.release(6);
+
+            break;
+
+        case BUTTON_7_KEY:
+            Gamepad.release(7);
+
+            break;
+    }
+
+    Gamepad.write();
 }
 
 class : public KeyboardReportParser {
 public:
-    virtual void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
-        KeyReport *report = (KeyReport*)(buf);
-
-#if OUTPUT_TO_SERIAL
-        Serial.print("src modifiers:  ");
-        Serial.println(report->modifiers, HEX);
-        Serial.print("src keys:  ");
-        for (int i = 0; i < NUM_REPORT_KEYS; i++) {
-            Serial.print(report->keys[i], HEX);
-            Serial.print(" ");
-        }
-        Serial.println("");
-#endif
-
-        if (removeFromKeyReport(report, KEY_CAPS_LOCK)) {
-            report->modifiers |= MODIFIER_LEFT_CTRL;
-        }
-
-#if OUTPUT_TO_SERIAL
-        Serial.print("dest modifiers:  ");
-        Serial.println(report->modifiers, HEX);
-        Serial.print("dest keys:  ");
-        for (int i = 0; i < NUM_REPORT_KEYS; i++) {
-            Serial.print(report->keys[i], HEX);
-            Serial.print(" ");
-        }
-        Serial.println("");
-#endif
-
-        KeyboardReportParser::Parse(hid, is_rpt_id, len, (uint8_t*)report);
-
-#if OUTPUT_TO_SERIAL
-        Serial.println("");
-#endif
-    }
-
     virtual void OnKeyDown(uint8_t modifiers, uint8_t key) {
-#if OUTPUT_TO_SERIAL
-        Serial.print("key down:  ");
-        Serial.println(key, HEX);
-#endif
-
         if (handleModeSwitch(modifiers, key)) {
             releaseAllKeys();
 
             return;
         }
 
-        switch (keyboardState.currentMode) {
-            case MODE_NEUTRAL:
-                pressKey(key);
-                return;
-
-            case MODE_DUDRACK:
-                dudrackKeyDown(key);
-                return;
-
-            case MODE_STG:
-                stgKeyDown(key);
-                return;
-        }
+        keyDown(key);
     }
 
     virtual void OnKeyUp(uint8_t modifiers, uint8_t key) {
-#if OUTPUT_TO_SERIAL
-        Serial.print("key up:  ");
-        Serial.println(key, HEX);
-#endif
-
-        switch (keyboardState.currentMode) {
-            case MODE_NEUTRAL:
-                releaseKey(key);
-                return;
-
-            case MODE_DUDRACK:
-                dudrackKeyUp(key);
-                return;
-
-            case MODE_STG:
-                stgKeyUp(key);
-                return;
-        }
+        keyUp(key);
     }
 
     virtual void OnControlKeysChanged(uint8_t before, uint8_t after) {

#define MAPPING_COUNT 2

#define STICK_NEUTRAL 0
#define STICK_DOWN 1
#define STICK_UP -1
#define STICK_LEFT -1
#define STICK_RIGHT 1

#define STICK_DOWN_KEY KEY_Z
#define STICK_UP_KEY KEY_X
#define STICK_LEFT_KEY KEY_AT
#define STICK_RIGHT_KEY KEY_BRACKET_OPEN
#define BUTTON_0_KEY KEY_ENTER
#define BUTTON_1_MODIFIER bmRightAlt
#define BUTTON_2_KEY KEY_PRINT_SCREEN
#define BUTTON_3_MODIFIER bmLeftShift
#define BUTTON_4_MODIFIER bmLeftCtrl
#define BUTTON_5_KEY KEY_A
#define BUTTON_6_KEY KEY_SPACE

USB    Usb;
USBHub Hub(&Usb);

#include <hidboot.h>
#include <hiduniversal.h>
#include <usbhub.h>

#include <HID-Project.h>

#define OUTPUT_TO_SERIAL 0

#define NUM_REPORT_KEYS 6

#define KEY_COLON         KEY_QUOTE
#define KEY_AT            KEY_LEFT_BRACE
#define KEY_LEFT_BRACKET  KEY_RIGHT_BRACE
#define KEY_RIGHT_BRACKET KEY_NON_US_NUM
#define KEY_HAN_ZEN       KEY_TILDE
#define KEY_HAT           KEY_EQUAL
#define KEY_JP_BACKSLASH  KEY_INTERNATIONAL1
#define KEY_HIRAGANA      KEY_INTERNATIONAL2
#define KEY_YEN           KEY_INTERNATIONAL3
#define KEY_HENKAN        KEY_INTERNATIONAL4
#define KEY_MUHENKAN      KEY_INTERNATIONAL5

#define KEY_COUNT 0xE8

