Commits

Nick Massey committed 69cc971

Handle keybinds completely differently, allows shared keybinds between input sources.
Initialize NES work ram in same manor as FCEUX.
Add fast keybind dialog for NES standard controllers.

Comments (0)

Files changed (15)

DirectXEmu/DirectXEmu.csproj

     <Compile Include="PaletteConfig.Designer.cs">
       <DependentUpon>PaletteConfig.cs</DependentUpon>
     </Compile>
+    <Compile Include="PollKey.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="PollKey.Designer.cs">
+      <DependentUpon>PollKey.cs</DependentUpon>
+    </Compile>
     <Compile Include="RomPatching.cs" />
     <Compile Include="Video\DX10Renderer.cs" />
     <Compile Include="Video\DX9Renderer.cs" />
       <DependentUpon>PatternTablePreview.cs</DependentUpon>
       <SubType>Designer</SubType>
     </EmbeddedResource>
+    <EmbeddedResource Include="PollKey.resx">
+      <DependentUpon>PollKey.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="Program.resx">
       <DependentUpon>Program.cs</DependentUpon>
       <SubType>Designer</SubType>

DirectXEmu/EmuConfig.cs

             defaults["showFPS"] = "0";
             defaults["showInput"] = "0";
             defaults["helpFile"] = @"Emu-o-Tron.chm";
-            defaults["player1Up"] = "Up";
-            defaults["player1Down"] = "Down";
-            defaults["player1Left"] = "Left";
-            defaults["player1Right"] = "Right";
-            defaults["player1Start"] = "Return";
-            defaults["player1Select"] = "OemQuotes";
-            defaults["player1A"] = "Z";
-            defaults["player1B"] = "X";
-            defaults["player1TurboA"] = "A";
-            defaults["player1TurboB"] = "S";
-            defaults["player2Up"] = "NumPad8";
-            defaults["player2Down"] = "NumPad5";
-            defaults["player2Left"] = "NumPad4";
-            defaults["player2Right"] = "NumPad6";
-            defaults["player2Start"] = "NumPad7";
-            defaults["player2Select"] = "NumPad9";
-            defaults["player2A"] = "NumPad1";
-            defaults["player2B"] = "NumPad3";
-            defaults["player2TurboA"] = "Home";
-            defaults["player2TurboB"] = "End";
-            defaults["fastForward"] = "ShiftKey";
-            defaults["rewind"] = "Tab";
-            defaults["saveState"] = "D1";
-            defaults["loadState"] = "D2";
-            defaults["pause"] = "Space";
-            defaults["restart"] = "Back";
-            defaults["power"] = "Delete";
+            defaults["player1Up"] = EmuKeys.UpArrow.ToString();
+            defaults["player1Down"] = EmuKeys.DownArrow.ToString();
+            defaults["player1Left"] = EmuKeys.LeftArrow.ToString();
+            defaults["player1Right"] = EmuKeys.RightArrow.ToString();
+            defaults["player1Start"] = EmuKeys.Return.ToString();
+            defaults["player1Select"] = EmuKeys.Apostrophe.ToString();
+            defaults["player1A"] = EmuKeys.Z.ToString();
+            defaults["player1B"] = EmuKeys.X.ToString();
+            defaults["player1TurboA"] = EmuKeys.A.ToString();
+            defaults["player1TurboB"] = EmuKeys.S.ToString();
+            defaults["player2Up"] = EmuKeys.NumberPad8.ToString();
+            defaults["player2Down"] = EmuKeys.NumberPad5.ToString();
+            defaults["player2Left"] = EmuKeys.NumberPad4.ToString();
+            defaults["player2Right"] = EmuKeys.NumberPad6.ToString();
+            defaults["player2Start"] = EmuKeys.NumberPad7.ToString();
+            defaults["player2Select"] = EmuKeys.NumberPad9.ToString();
+            defaults["player2A"] = EmuKeys.NumberPad1.ToString();
+            defaults["player2B"] = EmuKeys.NumberPad3.ToString();
+            defaults["player2TurboA"] = EmuKeys.Home.ToString();
+            defaults["player2TurboB"] = EmuKeys.End.ToString();
+            defaults["fastForward"] = EmuKeys.LeftShift.ToString();
+            defaults["rewind"] = EmuKeys.Tab.ToString();
+            defaults["saveState"] = EmuKeys.D1.ToString();
+            defaults["loadState"] = EmuKeys.D2.ToString();
+            defaults["pause"] = EmuKeys.Space.ToString();
+            defaults["restart"] = EmuKeys.Backspace.ToString();
+            defaults["power"] = EmuKeys.Delete.ToString();
             defaults["scaler"] = "sizeable";
             defaults["width"] = "528";
             defaults["height"] = "542";

DirectXEmu/EmuoTron/NESCore.cs

             lastRead = 0;
             for (int i = 0; i < 0x800; i++)
             {
-                Memory[i] = 0;
+                Memory[i] = (byte)((i & 0x04) == 0 ? 0x00 : 0xFF);
             }
             interruptReset = false;
             PPU.Power();

DirectXEmu/Input/DXInput.cs

         MouseState mouseState;
         Form inputSource;
         List<Key> pressedKeys = new List<Key>();
-        Dictionary<Key, Keys> dxTranslate = new Dictionary<Key, Keys>();
-        MouseArgs currentMouse;
+        Dictionary<Key, EmuKeys> dxTranslate = new Dictionary<Key, EmuKeys>();
+        private int mouseX;
+        private int mouseY;
+        private bool[] currentMouseButtons = new bool[5];
         Joystick joystick;
         JoystickState joystickState;
         bool joystickAttached = false;
 
+        public event InputHandler InputEvent;
+        public event InputScalerHandler InputScalerEvent;
 
-        public event KeyHandler KeyDownEvent;
-        public event KeyHandler KeyUpEvent;
-        public event MouseHandler MouseMoveEvent;
-        public event MouseHandler MouseDownEvent;
-        public event MouseHandler MouseUpEvent;
-
+        private bool joyUpPressed;
+        private bool joyDownPressed;
         private bool joyLeftPressed;
         private bool joyRightPressed;
-        private bool joyUpPressed;
-        private bool joyDownPressed;
-        private bool joy0Pressed;
-        private bool joy1Pressed;
-        private bool joy2Pressed;
-        private bool joy3Pressed;
+        private bool[] currentJoyButtons = new bool[10];
 
 
         public DXInput(Form inputSource)
                 if (joystickState.X < 0x3FFF)
                 {
                     if (!joyLeftPressed)
-                        KeyDownEvent(this, Keys.Left);
+                        InputEvent(EmuKeys.JoyLeft, true);
                     joyLeftPressed = true;
                 }
                 else
                 {
                     if (joyLeftPressed)
-                        KeyUpEvent(this, Keys.Left);
+                        InputEvent(EmuKeys.JoyLeft, false);
                     joyLeftPressed = false;
                 }
                 if (joystickState.X > 0xBFFF)
                 {
                     if (!joyRightPressed)
-                        KeyDownEvent(this, Keys.Right);
+                        InputEvent(EmuKeys.JoyRight, true);
                     joyRightPressed = true;
                 }
                 else
                 {
                     if (joyRightPressed)
-                        KeyUpEvent(this, Keys.Right);
+                        InputEvent(EmuKeys.JoyRight, false);
                     joyRightPressed = false;
                 }
                 if (joystickState.Y < 0x3FFF)
                 {
                     if (!joyUpPressed)
-                        KeyDownEvent(this, Keys.Up);
+                        InputEvent(EmuKeys.JoyUp, true);
                     joyUpPressed = true;
                 }
                 else
                 {
                     if (joyUpPressed)
-                        KeyUpEvent(this, Keys.Up);
+                        InputEvent(EmuKeys.JoyUp, false);
                     joyUpPressed = false;
                 }
                 if (joystickState.Y > 0xBFFF)
                 {
                     if (!joyDownPressed)
-                        KeyDownEvent(this, Keys.Down);
+                        InputEvent(EmuKeys.JoyDown, true);
                     joyDownPressed = true;
                 }
                 else
                 {
                     if (joyDownPressed)
-                        KeyUpEvent(this, Keys.Down);
+                        InputEvent(EmuKeys.JoyDown, false);
                     joyDownPressed = false;
                 }
 
                 bool[] buttons = joystickState.GetButtons();
 
-                if (buttons[0])
+                for (int i = 0; i < buttons.Length && i < 10; i++)
                 {
-                    if (!joy0Pressed)
-                        KeyDownEvent(this, Keys.X);
-                    joy0Pressed = true;
+                    if(buttons[i] != currentJoyButtons[i])
+                    {
+                        switch (i)
+                        {
+                            case 0:
+                                InputEvent(EmuKeys.Joy1, buttons[i]);
+                                break;
+                            case 1:
+                                InputEvent(EmuKeys.Joy2, buttons[i]);
+                                break;
+                            case 2:
+                                InputEvent(EmuKeys.Joy3, buttons[i]);
+                                break;
+                            case 3:
+                                InputEvent(EmuKeys.Joy4, buttons[i]);
+                                break;
+                            case 4:
+                                InputEvent(EmuKeys.Joy5, buttons[i]);
+                                break;
+                            case 5:
+                                InputEvent(EmuKeys.Joy6, buttons[i]);
+                                break;
+                            case 6:
+                                InputEvent(EmuKeys.Joy7, buttons[i]);
+                                break;
+                            case 7:
+                                InputEvent(EmuKeys.Joy8, buttons[i]);
+                                break;
+                            case 8:
+                                InputEvent(EmuKeys.Joy9, buttons[i]);
+                                break;
+                            case 9:
+                                InputEvent(EmuKeys.Joy10, buttons[i]);
+                                break;
+                        }
+                        currentJoyButtons[i] = buttons[i];
+                    }
                 }
-                else
-                {
-                    if (joy0Pressed)
-                        KeyUpEvent(this, Keys.X);
-                    joy0Pressed = false;
-                }
-
-                if (buttons[1])
-                {
-                    if (!joy1Pressed)
-                        KeyDownEvent(this, Keys.Z);
-                    joy1Pressed = true;
-                }
-                else
-                {
-                    if (joy1Pressed)
-                        KeyUpEvent(this, Keys.Z);
-                    joy1Pressed = false;
-                }
-
-                if (buttons[2])
-                {
-                    if (!joy2Pressed)
-                        KeyDownEvent(this, Keys.OemQuotes);
-                    joy2Pressed = true;
-                }
-                else
-                {
-                    if (joy2Pressed)
-                        KeyUpEvent(this, Keys.OemQuotes);
-                    joy2Pressed = false;
-                }
-
-                if (buttons[3])
-                {
-                    if (!joy3Pressed)
-                        KeyDownEvent(this, Keys.Return);
-                    joy3Pressed = true;
-                }
-                else
-                {
-                    if (joy3Pressed)
-                        KeyUpEvent(this, Keys.Return);
-                    joy3Pressed = false;
-                }
-
             }
             catch
             {
             try
             {
                 mouse.GetCurrentState(ref mouseState);
-                MouseArgs newMouse;
-                newMouse.Click = mouseState.IsPressed(0);
-                newMouse.X = Cursor.Position.X; //Not even going to bother with attempting to use crazy relative Direct Input mouse data
-                newMouse.Y = Cursor.Position.Y;
-                if (newMouse.Click != currentMouse.Click)
+                
+                bool[] buttons = mouseState.GetButtons();
+
+                for (int i = 0; i < buttons.Length && i < 5; i++)
                 {
-                    if (newMouse.Click)
-                        MouseDownEvent(this, newMouse);
-                    else
-                        MouseUpEvent(this, newMouse);
+                    if (buttons[i] != currentMouseButtons[i])
+                    {
+                        switch (i)
+                        {
+                            case 0:
+                                InputEvent(EmuKeys.Mouse1, buttons[i]);
+                                break;
+                            case 1:
+                                InputEvent(EmuKeys.Mouse2, buttons[i]);
+                                break;
+                            case 2:
+                                InputEvent(EmuKeys.Mouse3, buttons[i]);
+                                break;
+                            case 3:
+                                InputEvent(EmuKeys.Mouse4, buttons[i]);
+                                break;
+                            case 4:
+                                InputEvent(EmuKeys.Mouse5, buttons[i]);
+                                break;
+                        }
+                        currentMouseButtons[i] = buttons[i];
+                    }
                 }
-                if (newMouse.X != currentMouse.X || newMouse.Y != currentMouse.Y)
-                    MouseMoveEvent(this, newMouse);
-                currentMouse = newMouse;
+                int newMouseX = Cursor.Position.X; //Not even going to bother with attempting to use crazy relative Direct Input mouse data
+                int newMouseY = Cursor.Position.Y;
+                if (newMouseX != mouseX)
+                    InputScalerEvent(EmuKeys.MouseX, newMouseX);
+                if (newMouseY != mouseY)
+                    InputScalerEvent(EmuKeys.MouseY, newMouseY);
+                mouseX = newMouseX;
+                mouseY = newMouseY;
 
             }
             catch
                     if(keyState.IsPressed(key))
                     {
                         newPressedKeys.Add(key);
-                        if (!pressedKeys.Contains(key))
-                            KeyDownEvent(this, dxTranslate[key]);
+                        if (!pressedKeys.Contains(key) && dxTranslate.ContainsKey(key))
+                            InputEvent(dxTranslate[key], true);
                     }
                     else
                     {
-                        if (pressedKeys.Contains(key))
-                            KeyUpEvent(this, dxTranslate[key]);
+                        if (pressedKeys.Contains(key) && dxTranslate.ContainsKey(key))
+                            InputEvent(dxTranslate[key], false);
                     }
                 }
                 pressedKeys = newPressedKeys;
 
         private void LoadKeyTranslations() //There is a chance that mshome keyboard bug is in play here rendering this useless on many other PCs, but my default keybinds work for me so whatever.
         {
-            dxTranslate[Key.A] = Keys.A;
-            dxTranslate[Key.Apostrophe] = Keys.OemQuotes;
-            dxTranslate[Key.B] = Keys.B;
-            dxTranslate[Key.Backslash] = Keys.OemBackslash;
-            dxTranslate[Key.Backspace] = Keys.Back;
-            dxTranslate[Key.C] = Keys.C;
-            dxTranslate[Key.CapsLock] = Keys.CapsLock;
-            dxTranslate[Key.Colon] = Keys.OemQuotes;
-            dxTranslate[Key.Comma] = Keys.Oemcomma;
-            dxTranslate[Key.D] = Keys.D;
-            dxTranslate[Key.D0] = Keys.D0;
-            dxTranslate[Key.D1] = Keys.D1;
-            dxTranslate[Key.D2] = Keys.D2;
-            dxTranslate[Key.D3] = Keys.D3;
-            dxTranslate[Key.D4] = Keys.D4;
-            dxTranslate[Key.D5] = Keys.D5;
-            dxTranslate[Key.D6] = Keys.D6;
-            dxTranslate[Key.D7] = Keys.D7;
-            dxTranslate[Key.D8] = Keys.D8;
-            dxTranslate[Key.D9] = Keys.D9;
-            dxTranslate[Key.Delete] = Keys.Delete;
-            dxTranslate[Key.DownArrow] = Keys.Down;
-            dxTranslate[Key.E] = Keys.E;
-            dxTranslate[Key.End] = Keys.End;
-            dxTranslate[Key.PreviousTrack] = Keys.Oemplus; //*************CHECK
-            dxTranslate[Key.Escape] = Keys.Escape;
-            dxTranslate[Key.F] = Keys.F;
-            dxTranslate[Key.F1] = Keys.F1;
-            dxTranslate[Key.F2] = Keys.F2;
-            dxTranslate[Key.F3] = Keys.F3;
-            dxTranslate[Key.F4] = Keys.F4;
-            dxTranslate[Key.F5] = Keys.F5;
-            dxTranslate[Key.F6] = Keys.F6;
-            dxTranslate[Key.F7] = Keys.F7;
-            dxTranslate[Key.F8] = Keys.F8;
-            dxTranslate[Key.F9] = Keys.F9;
-            dxTranslate[Key.F10] = Keys.F10;
-            dxTranslate[Key.F11] = Keys.F11;
-            dxTranslate[Key.F12] = Keys.F12;
-            dxTranslate[Key.F13] = Keys.F13;
-            dxTranslate[Key.F14] = Keys.F14;
-            dxTranslate[Key.F15] = Keys.F15;
-            dxTranslate[Key.G] = Keys.G;
-            dxTranslate[Key.Kanji] = Keys.Oemtilde;
-            dxTranslate[Key.H] = Keys.H;
-            dxTranslate[Key.Home] = Keys.Home;
-            dxTranslate[Key.I] = Keys.I;
-            dxTranslate[Key.Insert] = Keys.Insert;
-            dxTranslate[Key.J] = Keys.J;
-            dxTranslate[Key.K] = Keys.K;
-            dxTranslate[Key.L] = Keys.L;
-            dxTranslate[Key.LeftAlt] = Keys.Alt;
-            dxTranslate[Key.LeftArrow] = Keys.Left;
-            dxTranslate[Key.LeftBracket] = Keys.OemCloseBrackets;
-            dxTranslate[Key.AT] = Keys.OemOpenBrackets;//WEEEEIRD
-            dxTranslate[Key.LeftControl] = Keys.LControlKey;
-            dxTranslate[Key.LeftShift] = Keys.ShiftKey;
-            dxTranslate[Key.LeftWindowsKey] = Keys.LWin;
-            dxTranslate[Key.M] = Keys.M;
-            dxTranslate[Key.Minus] = Keys.Subtract;
-            dxTranslate[Key.N] = Keys.N;
-            dxTranslate[Key.NumberLock] = Keys.NumLock;
-            dxTranslate[Key.NumberPad0] = Keys.NumPad0;
-            dxTranslate[Key.NumberPad1] = Keys.NumPad1;
-            dxTranslate[Key.NumberPad2] = Keys.NumPad2;
-            dxTranslate[Key.NumberPad3] = Keys.NumPad3;
-            dxTranslate[Key.NumberPad4] = Keys.NumPad4;
-            dxTranslate[Key.NumberPad5] = Keys.NumPad5;
-            dxTranslate[Key.NumberPad6] = Keys.NumPad6;
-            dxTranslate[Key.NumberPad7] = Keys.NumPad7;
-            dxTranslate[Key.NumberPad8] = Keys.NumPad8;
-            dxTranslate[Key.NumberPad9] = Keys.NumPad9;
-            dxTranslate[Key.NumberPadComma] = Keys.Oemcomma;
-            dxTranslate[Key.NumberPadEnter] = Keys.Enter;//CHECK
-            dxTranslate[Key.NumberPadMinus] = Keys.Subtract;
-            dxTranslate[Key.NumberPadPeriod] = Keys.OemPeriod;
-            dxTranslate[Key.NumberPadPlus] = Keys.Oemplus;
-            dxTranslate[Key.NumberPadSlash] = Keys.Divide;
-            dxTranslate[Key.NumberPadStar] = Keys.Multiply;
-            dxTranslate[Key.O] = Keys.O;
-            dxTranslate[Key.Oem102] = Keys.Oem102;
-            dxTranslate[Key.P] = Keys.P;
-            dxTranslate[Key.PageDown] = Keys.PageDown;
-            dxTranslate[Key.PageUp] = Keys.PageUp;
-            dxTranslate[Key.Pause] = Keys.Pause;
-            dxTranslate[Key.Period] = Keys.OemPeriod;
-            dxTranslate[Key.PrintScreen] = Keys.PrintScreen;
-            dxTranslate[Key.Q] = Keys.Q;
-            dxTranslate[Key.R] = Keys.R;
-            dxTranslate[Key.Return] = Keys.Return;
-            dxTranslate[Key.RightAlt] = Keys.Alt;
-            dxTranslate[Key.RightArrow] = Keys.Right;
-            dxTranslate[Key.RightBracket] = Keys.OemBackslash;
-            dxTranslate[Key.RightControl] = Keys.RControlKey;
-            dxTranslate[Key.RightShift] = Keys.ShiftKey;
-            dxTranslate[Key.RightWindowsKey] = Keys.RWin;
-            dxTranslate[Key.S] = Keys.S;
-            dxTranslate[Key.ScrollLock] = Keys.Scroll;
-            dxTranslate[Key.Semicolon] = Keys.OemSemicolon;
-            dxTranslate[Key.Slash] = Keys.Divide;
-            dxTranslate[Key.Space] = Keys.Space;
-            dxTranslate[Key.T] = Keys.T;
-            dxTranslate[Key.Tab] = Keys.Tab;
-            dxTranslate[Key.U] = Keys.U;
-            dxTranslate[Key.UpArrow] = Keys.Up;
-            dxTranslate[Key.V] = Keys.V;
-            dxTranslate[Key.W] = Keys.W;
-            dxTranslate[Key.X] = Keys.X;
-            dxTranslate[Key.Y] = Keys.Y;
-            dxTranslate[Key.Z] = Keys.Z;
+            dxTranslate[Key.A] = EmuKeys.A;
+            dxTranslate[Key.Colon] = EmuKeys.Apostrophe;
+            dxTranslate[Key.B] = EmuKeys.B;
+            dxTranslate[Key.Backslash] = EmuKeys.Backslash;
+            dxTranslate[Key.Backspace] = EmuKeys.Backspace;
+            dxTranslate[Key.C] = EmuKeys.C;
+            dxTranslate[Key.CapsLock] = EmuKeys.CapsLock;
+            dxTranslate[Key.Comma] = EmuKeys.Comma;
+            dxTranslate[Key.D] = EmuKeys.D;
+            dxTranslate[Key.D0] = EmuKeys.D0;
+            dxTranslate[Key.D1] = EmuKeys.D1;
+            dxTranslate[Key.D2] = EmuKeys.D2;
+            dxTranslate[Key.D3] = EmuKeys.D3;
+            dxTranslate[Key.D4] = EmuKeys.D4;
+            dxTranslate[Key.D5] = EmuKeys.D5;
+            dxTranslate[Key.D6] = EmuKeys.D6;
+            dxTranslate[Key.D7] = EmuKeys.D7;
+            dxTranslate[Key.D8] = EmuKeys.D8;
+            dxTranslate[Key.D9] = EmuKeys.D9;
+            dxTranslate[Key.Delete] = EmuKeys.Delete;
+            dxTranslate[Key.DownArrow] = EmuKeys.DownArrow;
+            dxTranslate[Key.E] = EmuKeys.E;
+            dxTranslate[Key.End] = EmuKeys.End;
+            dxTranslate[Key.Escape] = EmuKeys.Escape;
+            dxTranslate[Key.F] = EmuKeys.F;
+            dxTranslate[Key.F1] = EmuKeys.F1;
+            dxTranslate[Key.F2] = EmuKeys.F2;
+            dxTranslate[Key.F3] = EmuKeys.F3;
+            dxTranslate[Key.F4] = EmuKeys.F4;
+            dxTranslate[Key.F5] = EmuKeys.F5;
+            dxTranslate[Key.F6] = EmuKeys.F6;
+            dxTranslate[Key.F7] = EmuKeys.F7;
+            dxTranslate[Key.F8] = EmuKeys.F8;
+            dxTranslate[Key.F9] = EmuKeys.F9;
+            dxTranslate[Key.F10] = EmuKeys.F10;
+            dxTranslate[Key.F11] = EmuKeys.F11;
+            dxTranslate[Key.F12] = EmuKeys.F12;
+            dxTranslate[Key.G] = EmuKeys.G;
+            dxTranslate[Key.Kanji] = EmuKeys.Grave;
+            dxTranslate[Key.H] = EmuKeys.H;
+            dxTranslate[Key.Home] = EmuKeys.Home;
+            dxTranslate[Key.I] = EmuKeys.I;
+            dxTranslate[Key.Insert] = EmuKeys.Insert;
+            dxTranslate[Key.J] = EmuKeys.J;
+            dxTranslate[Key.K] = EmuKeys.K;
+            dxTranslate[Key.L] = EmuKeys.L;
+            dxTranslate[Key.LeftAlt] = EmuKeys.LeftAlt;
+            dxTranslate[Key.LeftArrow] = EmuKeys.LeftArrow;
+            dxTranslate[Key.LeftBracket] = EmuKeys.RightBracket;
+            dxTranslate[Key.AT] = EmuKeys.LeftBracket;
+            dxTranslate[Key.LeftControl] = EmuKeys.LeftControl;
+            dxTranslate[Key.LeftShift] = EmuKeys.LeftShift;
+            dxTranslate[Key.LeftWindowsKey] = EmuKeys.LeftWindowsKey;
+            dxTranslate[Key.M] = EmuKeys.M;
+            dxTranslate[Key.Minus] = EmuKeys.Minus;
+            dxTranslate[Key.N] = EmuKeys.N;
+            dxTranslate[Key.NumberLock] = EmuKeys.NumberLock;
+            dxTranslate[Key.NumberPad0] = EmuKeys.NumberPad0;
+            dxTranslate[Key.NumberPad1] = EmuKeys.NumberPad1;
+            dxTranslate[Key.NumberPad2] = EmuKeys.NumberPad2;
+            dxTranslate[Key.NumberPad3] = EmuKeys.NumberPad3;
+            dxTranslate[Key.NumberPad4] = EmuKeys.NumberPad4;
+            dxTranslate[Key.NumberPad5] = EmuKeys.NumberPad5;
+            dxTranslate[Key.NumberPad6] = EmuKeys.NumberPad6;
+            dxTranslate[Key.NumberPad7] = EmuKeys.NumberPad7;
+            dxTranslate[Key.NumberPad8] = EmuKeys.NumberPad8;
+            dxTranslate[Key.NumberPad9] = EmuKeys.NumberPad9;
+            dxTranslate[Key.NumberPadEnter] = EmuKeys.NumberPadEnter;
+            dxTranslate[Key.NumberPadMinus] = EmuKeys.NumberPadMinus;
+            dxTranslate[Key.NumberPadPeriod] = EmuKeys.NumberPadPeriod;
+            dxTranslate[Key.NumberPadPlus] = EmuKeys.NumberPadPlus;
+            dxTranslate[Key.NumberPadSlash] = EmuKeys.NumberPadSlash;
+            dxTranslate[Key.NumberPadStar] = EmuKeys.NumberPadStar;
+            dxTranslate[Key.O] = EmuKeys.O;
+            dxTranslate[Key.P] = EmuKeys.P;
+            dxTranslate[Key.PageDown] = EmuKeys.PageDown;
+            dxTranslate[Key.PageUp] = EmuKeys.PageUp;
+            dxTranslate[Key.Pause] = EmuKeys.Pause;
+            dxTranslate[Key.Period] = EmuKeys.Period;
+            dxTranslate[Key.PrintScreen] = EmuKeys.PrintScreen;
+            dxTranslate[Key.Q] = EmuKeys.Q;
+            dxTranslate[Key.R] = EmuKeys.R;
+            dxTranslate[Key.Return] = EmuKeys.Return;
+            dxTranslate[Key.RightAlt] = EmuKeys.RightAlt;
+            dxTranslate[Key.RightArrow] = EmuKeys.RightArrow;
+            dxTranslate[Key.RightBracket] = EmuKeys.Backslash;
+            dxTranslate[Key.RightControl] = EmuKeys.RightControl;
+            dxTranslate[Key.RightShift] = EmuKeys.RightShift;
+            dxTranslate[Key.RightWindowsKey] = EmuKeys.RightWindowsKey;
+            dxTranslate[Key.S] = EmuKeys.S;
+            dxTranslate[Key.ScrollLock] = EmuKeys.ScrollLock;
+            dxTranslate[Key.Semicolon] = EmuKeys.Semicolon;
+            dxTranslate[Key.Slash] = EmuKeys.Slash;
+            dxTranslate[Key.Space] = EmuKeys.Space;
+            dxTranslate[Key.T] = EmuKeys.T;
+            dxTranslate[Key.Tab] = EmuKeys.Tab;
+            dxTranslate[Key.U] = EmuKeys.U;
+            dxTranslate[Key.UpArrow] = EmuKeys.UpArrow;
+            dxTranslate[Key.V] = EmuKeys.V;
+            dxTranslate[Key.W] = EmuKeys.W;
+            dxTranslate[Key.X] = EmuKeys.X;
+            dxTranslate[Key.Y] = EmuKeys.Y;
+            dxTranslate[Key.Z] = EmuKeys.Z;
         }
     }
 }

DirectXEmu/Input/IInput.cs

 
 namespace DirectXEmu
 {
-    interface IInput
+    public interface IInput
     {
         void Create();
         void Reset();
         void MainLoop();
         void Destroy();
-        event KeyHandler KeyDownEvent;
-        event KeyHandler KeyUpEvent;
-        event MouseHandler MouseMoveEvent;
-        event MouseHandler MouseDownEvent;
-        event MouseHandler MouseUpEvent;
+        event InputHandler InputEvent;
+        event InputScalerHandler InputScalerEvent;
     }
-    public struct MouseArgs
+
+    public delegate void InputHandler(EmuKeys key, bool pressed);
+    public delegate void InputScalerHandler(EmuKeys key, int value);
+
+
+    public enum EmuKeys
     {
-        public int X;
-        public int Y;
-        public bool Click;
+        None,
+        D0,
+        D1,
+        D2,
+        D3,
+        D4,
+        D5,
+        D6,
+        D7,
+        D8,
+        D9,
+        A,
+        B,
+        C,
+        D,
+        E,
+        F,
+        G,
+        H,
+        I,
+        J,
+        K,
+        L,
+        M,
+        N,
+        O,
+        P,
+        Q,
+        R,
+        S,
+        T,
+        U,
+        V,
+        W,
+        X,
+        Y,
+        Z,
+        Apostrophe,
+        Backspace,
+        Backslash,
+        CapsLock,
+        Comma,
+        Delete,
+        DownArrow,
+        End,
+        Equals,
+        Escape,
+        F1,
+        F2,
+        F3,
+        F4,
+        F5,
+        F6,
+        F7,
+        F8,
+        F9,
+        F10,
+        F11,
+        F12,
+        Grave,
+        Home,
+        Insert,
+        LeftBracket,
+        LeftControl,
+        LeftArrow,
+        LeftAlt,
+        LeftShift,
+        LeftWindowsKey,
+        Minus,
+        NumberLock,
+        NumberPad0,
+        NumberPad1,
+        NumberPad2,
+        NumberPad3,
+        NumberPad4,
+        NumberPad5,
+        NumberPad6,
+        NumberPad7,
+        NumberPad8,
+        NumberPad9,
+        NumberPadEnter,
+        NumberPadMinus,
+        NumberPadPeriod,
+        NumberPadPlus,
+        NumberPadSlash,
+        NumberPadStar,
+        PageDown,
+        PageUp,
+        Pause,
+        Period,
+        RightBracket,
+        RightControl,
+        Return,
+        RightArrow,
+        RightAlt,
+        RightShift,
+        RightWindowsKey,
+        ScrollLock,
+        Semicolon,
+        Slash,
+        Space,
+        PrintScreen,
+        Tab,
+        UpArrow,
+        Mouse1,
+        Mouse2,
+        Mouse3,
+        Mouse4,
+        Mouse5,
+        MouseX,
+        MouseY,
+        MouseScroll,
+        Joy1,
+        Joy2,
+        Joy3,
+        Joy4,
+        Joy5,
+        Joy6,
+        Joy7,
+        Joy8,
+        Joy9,
+        Joy10,
+        JoyUp,
+        JoyDown,
+        JoyLeft,
+        JoyRight
     }
-    public delegate void KeyHandler(object sender, Keys key);
-    public delegate void MouseHandler(object sender, MouseArgs mouse);
-
 }

DirectXEmu/Input/NullInput.cs

     {
         #region IInput Members
 
+        public event InputHandler InputEvent;
+        public event InputScalerHandler InputScalerEvent;
+
         public void Create()
         {
         }
         {
         }
 
-        public event KeyHandler KeyDownEvent;
-
-        public event KeyHandler KeyUpEvent;
-
-        public event MouseHandler MouseMoveEvent;
-
-        public event MouseHandler MouseDownEvent;
-
-        public event MouseHandler MouseUpEvent;
-
         #endregion
     }
 }

DirectXEmu/Input/WinInput.cs

     {
         Control keyboardSource;
         Control mouseSource;
-        MouseArgs currentMouse;
-        MouseArgs newMouse;
+
+        int mouseX;
+        int mouseY;
+
+        bool[] currentMouseButtons = new bool[5];
+        bool[] newMouseButtons = new bool[5];
 
         List<Keys> pressedKeys = new List<Keys>();
         List<Keys> releasedKeys = new List<Keys>();
 
+        Dictionary<Keys, EmuKeys> winTranslate = new Dictionary<Keys, EmuKeys>();
 
-        public event KeyHandler KeyDownEvent;
-        public event KeyHandler KeyUpEvent;
-        public event MouseHandler MouseMoveEvent;
-        public event MouseHandler MouseDownEvent;
-        public event MouseHandler MouseUpEvent;
+        public event InputHandler InputEvent;
+        public event InputScalerHandler InputScalerEvent;
 
         public WinInput(Control keyboardSource, Control mouseSource)
         {
             this.keyboardSource = keyboardSource;
             this.mouseSource = mouseSource;
+            LoadKeyTranslations();
         }
         public void Create()
         {
 
         void inputSource_MouseUp(object sender, MouseEventArgs e)
         {
-            if (e.Button == MouseButtons.Left)
-                newMouse.Click = false;
+            switch (e.Button)
+            {
+                case MouseButtons.Left:
+                    newMouseButtons[0] = false;
+                    break;
+                case MouseButtons.Right:
+                    newMouseButtons[1] = false;
+                    break;
+                case MouseButtons.Middle:
+                    newMouseButtons[2] = false;
+                    break;
+                case MouseButtons.XButton1:
+                    newMouseButtons[3] = false;
+                    break;
+                case MouseButtons.XButton2:
+                    newMouseButtons[4] = false;
+                    break;
+            }
         }
 
         void inputSource_MouseDown(object sender, MouseEventArgs e)
         {
-            if (e.Button == MouseButtons.Left)
-                newMouse.Click = true;
+            switch (e.Button)
+            {
+                case MouseButtons.Left:
+                    newMouseButtons[0] = true;
+                    break;
+                case MouseButtons.Right:
+                    newMouseButtons[1] = true;
+                    break;
+                case MouseButtons.Middle:
+                    newMouseButtons[2] = true;
+                    break;
+                case MouseButtons.XButton1:
+                    newMouseButtons[3] = true;
+                    break;
+                case MouseButtons.XButton2:
+                    newMouseButtons[4] = true;
+                    break;
+            }
         }
 
         void inputSource_KeyUp(object sender, KeyEventArgs e)
         public void MainLoop()
         {
             foreach (Keys key in pressedKeys)
-                KeyDownEvent(this, key);
+            {
+                if (winTranslate.ContainsKey(key))
+                    InputEvent(winTranslate[key], true);
+            }
             pressedKeys.Clear();
             foreach (Keys key in releasedKeys)
-                KeyUpEvent(this, key);
+            {
+                if (winTranslate.ContainsKey(key))
+                    InputEvent(winTranslate[key], false);
+            }
             releasedKeys.Clear();
-            newMouse.X = Cursor.Position.X;
-            newMouse.Y = Cursor.Position.Y;
-            if (newMouse.Click != currentMouse.Click)
+            for (int i = 0; i < newMouseButtons.Length; i++)
             {
-                if (newMouse.Click)
-                    MouseDownEvent(this, newMouse);
-                else
-                    MouseUpEvent(this, newMouse);
+                if (newMouseButtons[i] != currentMouseButtons[i])
+                {
+                    switch (i)
+                    {
+                        case 0:
+                            InputEvent(EmuKeys.Mouse1, newMouseButtons[i]);
+                            break;
+                        case 1:
+                            InputEvent(EmuKeys.Mouse2, newMouseButtons[i]);
+                            break;
+                        case 2:
+                            InputEvent(EmuKeys.Mouse3, newMouseButtons[i]);
+                            break;
+                        case 3:
+                            InputEvent(EmuKeys.Mouse4, newMouseButtons[i]);
+                            break;
+                        case 4:
+                            InputEvent(EmuKeys.Mouse5, newMouseButtons[i]);
+                            break;
+                    }
+                    currentMouseButtons[i] = newMouseButtons[i];
+                }
             }
-            if (newMouse.X != currentMouse.X || newMouse.Y != currentMouse.Y)
-                MouseMoveEvent(this, newMouse);
-            currentMouse = newMouse;
+
+            int newMouseX = Cursor.Position.X;
+            int newMouseY = Cursor.Position.Y;
+            if (newMouseX != mouseX)
+                InputScalerEvent(EmuKeys.MouseX, newMouseX);
+            if (newMouseY != mouseY)
+                InputScalerEvent(EmuKeys.MouseY, newMouseY);
+            mouseX = newMouseX;
+            mouseY = newMouseY;
         }
 
         public void Destroy()
         {
         }
+
+        private void LoadKeyTranslations()
+        {
+            winTranslate[Keys.A] = EmuKeys.A;
+            winTranslate[Keys.OemQuotes] = EmuKeys.Apostrophe;
+            winTranslate[Keys.B] = EmuKeys.B;
+            winTranslate[Keys.OemPipe] = EmuKeys.Backslash;
+            winTranslate[Keys.Back] = EmuKeys.Backspace;
+            winTranslate[Keys.C] = EmuKeys.C;
+            winTranslate[Keys.CapsLock] = EmuKeys.CapsLock;
+            winTranslate[Keys.Oemcomma] = EmuKeys.Comma;
+            winTranslate[Keys.D] = EmuKeys.D;
+            winTranslate[Keys.D0] = EmuKeys.D0;
+            winTranslate[Keys.D1] = EmuKeys.D1;
+            winTranslate[Keys.D2] = EmuKeys.D2;
+            winTranslate[Keys.D3] = EmuKeys.D3;
+            winTranslate[Keys.D4] = EmuKeys.D4;
+            winTranslate[Keys.D5] = EmuKeys.D5;
+            winTranslate[Keys.D6] = EmuKeys.D6;
+            winTranslate[Keys.D7] = EmuKeys.D7;
+            winTranslate[Keys.D8] = EmuKeys.D8;
+            winTranslate[Keys.D9] = EmuKeys.D9;
+            winTranslate[Keys.Delete] = EmuKeys.Delete;
+            winTranslate[Keys.Down] = EmuKeys.DownArrow;
+            winTranslate[Keys.E] = EmuKeys.E;
+            winTranslate[Keys.End] = EmuKeys.End;
+            winTranslate[Keys.Oemplus] = EmuKeys.Equals;
+            winTranslate[Keys.Escape] = EmuKeys.Escape;
+            winTranslate[Keys.F] = EmuKeys.F;
+            winTranslate[Keys.F1] = EmuKeys.F1;
+            winTranslate[Keys.F2] = EmuKeys.F2;
+            winTranslate[Keys.F3] = EmuKeys.F3;
+            winTranslate[Keys.F4] = EmuKeys.F4;
+            winTranslate[Keys.F5] = EmuKeys.F5;
+            winTranslate[Keys.F6] = EmuKeys.F6;
+            winTranslate[Keys.F7] = EmuKeys.F7;
+            winTranslate[Keys.F8] = EmuKeys.F8;
+            winTranslate[Keys.F9] = EmuKeys.F9;
+            winTranslate[Keys.F10] = EmuKeys.F10;
+            winTranslate[Keys.F11] = EmuKeys.F11;
+            winTranslate[Keys.F12] = EmuKeys.F12;
+            winTranslate[Keys.G] = EmuKeys.G;
+            winTranslate[Keys.Oemtilde] = EmuKeys.Grave;
+            winTranslate[Keys.H] = EmuKeys.H;
+            winTranslate[Keys.Home] = EmuKeys.Home;
+            winTranslate[Keys.I] = EmuKeys.I;
+            winTranslate[Keys.Insert] = EmuKeys.Insert;
+            winTranslate[Keys.J] = EmuKeys.J;
+            winTranslate[Keys.K] = EmuKeys.K;
+            winTranslate[Keys.L] = EmuKeys.L;
+            winTranslate[Keys.RButton | Keys.ShiftKey] = EmuKeys.LeftAlt;
+            winTranslate[Keys.Left] = EmuKeys.LeftArrow;
+            winTranslate[Keys.OemOpenBrackets] = EmuKeys.LeftBracket;
+            winTranslate[Keys.LButton | Keys.ShiftKey] = EmuKeys.LeftControl;
+            winTranslate[Keys.ShiftKey] = EmuKeys.LeftShift;
+            winTranslate[Keys.LWin] = EmuKeys.LeftWindowsKey;
+            winTranslate[Keys.M] = EmuKeys.M;
+            winTranslate[Keys.OemMinus] = EmuKeys.Minus;
+            winTranslate[Keys.N] = EmuKeys.N;
+            winTranslate[Keys.NumLock] = EmuKeys.NumberLock;
+            winTranslate[Keys.NumPad0] = EmuKeys.NumberPad0;
+            winTranslate[Keys.NumPad1] = EmuKeys.NumberPad1;
+            winTranslate[Keys.NumPad2] = EmuKeys.NumberPad2;
+            winTranslate[Keys.NumPad3] = EmuKeys.NumberPad3;
+            winTranslate[Keys.NumPad4] = EmuKeys.NumberPad4;
+            winTranslate[Keys.NumPad5] = EmuKeys.NumberPad5;
+            winTranslate[Keys.NumPad6] = EmuKeys.NumberPad6;
+            winTranslate[Keys.NumPad7] = EmuKeys.NumberPad7;
+            winTranslate[Keys.NumPad8] = EmuKeys.NumberPad8;
+            winTranslate[Keys.NumPad9] = EmuKeys.NumberPad9;
+            winTranslate[Keys.Enter] = EmuKeys.NumberPadEnter;
+            winTranslate[Keys.Subtract] = EmuKeys.NumberPadMinus;
+            winTranslate[Keys.Decimal] = EmuKeys.NumberPadPeriod;
+            winTranslate[Keys.Add] = EmuKeys.NumberPadPlus;
+            winTranslate[Keys.Divide] = EmuKeys.NumberPadSlash;
+            winTranslate[Keys.Multiply] = EmuKeys.NumberPadStar;
+            winTranslate[Keys.O] = EmuKeys.O;
+            winTranslate[Keys.P] = EmuKeys.P;
+            winTranslate[Keys.PageDown] = EmuKeys.PageDown;
+            winTranslate[Keys.PageUp] = EmuKeys.PageUp;
+            winTranslate[Keys.Pause] = EmuKeys.Pause;
+            winTranslate[Keys.OemPeriod] = EmuKeys.Period;
+            winTranslate[Keys.PrintScreen] = EmuKeys.PrintScreen;
+            winTranslate[Keys.Q] = EmuKeys.Q;
+            winTranslate[Keys.R] = EmuKeys.R;
+            winTranslate[Keys.Return] = EmuKeys.Return;
+            winTranslate[Keys.Right] = EmuKeys.RightArrow;
+            winTranslate[Keys.OemCloseBrackets] = EmuKeys.RightBracket;
+            winTranslate[Keys.RControlKey] = EmuKeys.RightControl;
+            winTranslate[Keys.RShiftKey] = EmuKeys.RightShift;
+            winTranslate[Keys.RWin] = EmuKeys.RightWindowsKey;
+            winTranslate[Keys.S] = EmuKeys.S;
+            winTranslate[Keys.Scroll] = EmuKeys.ScrollLock;
+            winTranslate[Keys.OemSemicolon] = EmuKeys.Semicolon;
+            winTranslate[Keys.OemQuestion] = EmuKeys.Slash;
+            winTranslate[Keys.Space] = EmuKeys.Space;
+            winTranslate[Keys.T] = EmuKeys.T;
+            winTranslate[Keys.Tab] = EmuKeys.Tab;
+            winTranslate[Keys.U] = EmuKeys.U;
+            winTranslate[Keys.Up] = EmuKeys.UpArrow;
+            winTranslate[Keys.V] = EmuKeys.V;
+            winTranslate[Keys.W] = EmuKeys.W;
+            winTranslate[Keys.X] = EmuKeys.X;
+            winTranslate[Keys.Y] = EmuKeys.Y;
+            winTranslate[Keys.Z] = EmuKeys.Z;
+        }
     }
 }

DirectXEmu/Input/XInInput.cs

         ControllerState currentPlayer1;
         ControllerState currentPlayer2;
 
+        public event InputHandler InputEvent;
+        public event InputScalerHandler InputScalerEvent;
+
         public void Create()
         {
             Reset();
 
                 if (newPlayer1.A != currentPlayer1.A)
                 {
-                    if (newPlayer1.A)
-                        KeyDownEvent(this, Keys.Z);
-                    else
-                        KeyUpEvent(this, Keys.Z);
+                    InputEvent(EmuKeys.Joy1, newPlayer1.A);
                 }
                 if (newPlayer1.B != currentPlayer1.B)
                 {
-                    if (newPlayer1.B)
-                        KeyDownEvent(this, Keys.X);
-                    else
-                        KeyUpEvent(this, Keys.X);
+                    InputEvent(EmuKeys.Joy2, newPlayer1.B);
                 }
                 if (newPlayer1.X != currentPlayer1.X)
                 {
-                    if (newPlayer1.X)
-                        KeyDownEvent(this, Keys.A);
-                    else
-                        KeyUpEvent(this, Keys.A);
+                    InputEvent(EmuKeys.Joy3, newPlayer1.X);
                 }
                 if (newPlayer1.Y != currentPlayer1.Y)
                 {
-                    if (newPlayer1.Y)
-                        KeyDownEvent(this, Keys.S);
-                    else
-                        KeyUpEvent(this, Keys.S);
+                    InputEvent(EmuKeys.Joy4, newPlayer1.Y);
                 }
                 if (newPlayer1.Up != currentPlayer1.Up)
                 {
-                    if (newPlayer1.Up)
-                        KeyDownEvent(this, Keys.Up);
-                    else
-                        KeyUpEvent(this, Keys.Up);
+                    InputEvent(EmuKeys.JoyUp, newPlayer1.Up);
                 }
                 if (newPlayer1.Down != currentPlayer1.Down)
                 {
-                    if (newPlayer1.Down)
-                        KeyDownEvent(this, Keys.Down);
-                    else
-                        KeyUpEvent(this, Keys.Down);
+                    InputEvent(EmuKeys.JoyDown, newPlayer1.Down);
                 }
                 if (newPlayer1.Left != currentPlayer1.Left)
                 {
-                    if (newPlayer1.Left)
-                        KeyDownEvent(this, Keys.Left);
-                    else
-                        KeyUpEvent(this, Keys.Left);
+                    InputEvent(EmuKeys.JoyLeft, newPlayer1.Left);
                 }
                 if (newPlayer1.Right != currentPlayer1.Right)
                 {
-                    if (newPlayer1.Right)
-                        KeyDownEvent(this, Keys.Right);
-                    else
-                        KeyUpEvent(this, Keys.Right);
+                    InputEvent(EmuKeys.JoyRight, newPlayer1.Right);
                 }
                 if (newPlayer1.Start != currentPlayer1.Start)
                 {
-                    if (newPlayer1.Start)
-                        KeyDownEvent(this, Keys.Return);
-                    else
-                        KeyUpEvent(this, Keys.Return);
+                    InputEvent(EmuKeys.Joy5, newPlayer1.Start);
                 }
                 if (newPlayer1.Back != currentPlayer1.Back)
                 {
-                    if (newPlayer1.Back)
-                        KeyDownEvent(this, Keys.OemQuotes);
-                    else
-                        KeyUpEvent(this, Keys.OemQuotes);
+                    InputEvent(EmuKeys.Joy6, newPlayer1.Back);
                 }
                 if (newPlayer1.LBumper != currentPlayer1.LBumper)
                 {
-                    if (newPlayer1.LBumper)
-                        KeyDownEvent(this, Keys.D2);
-                    else
-                        KeyUpEvent(this, Keys.D2);
+                    InputEvent(EmuKeys.Joy7, newPlayer1.LBumper);
                 }
                 if (newPlayer1.RBumper != currentPlayer1.RBumper)
                 {
-                    if (newPlayer1.RBumper)
-                        KeyDownEvent(this, Keys.D1);
-                    else
-                        KeyUpEvent(this, Keys.D1);
+                    InputEvent(EmuKeys.Joy8, newPlayer1.RBumper);
                 }
                 if (newPlayer1.LTrigger != currentPlayer1.LTrigger)
                 {
-                    if (newPlayer1.LTrigger)
-                        KeyDownEvent(this, Keys.Tab);
-                    else
-                        KeyUpEvent(this, Keys.Tab);
+                    InputEvent(EmuKeys.Joy9, newPlayer1.LTrigger);
                 }
                 if (newPlayer1.RTrigger != currentPlayer1.RTrigger)
                 {
-                    if (newPlayer1.RTrigger)
-                        KeyDownEvent(this, Keys.ShiftKey);
-                    else
-                        KeyUpEvent(this, Keys.ShiftKey);
+                    InputEvent(EmuKeys.Joy10, newPlayer1.RTrigger);
                 }
                 currentPlayer1 = newPlayer1;
             }
-
+            /*
             if (player2Controller.IsConnected)
             {
                 Gamepad x360State = player2Controller.GetState().Gamepad;
                         KeyUpEvent(this, Keys.NumPad9);
                 }
                 currentPlayer2 = newPlayer2;
-            }
+            }*/
         }
 
         public void Destroy()
         {
         }
 
-        public event KeyHandler KeyDownEvent;
-
-        public event KeyHandler KeyUpEvent;
-
-        public event MouseHandler MouseMoveEvent;
-
-        public event MouseHandler MouseDownEvent;
-
-        public event MouseHandler MouseUpEvent;
-
         struct ControllerState
         {
             public bool A;

DirectXEmu/Keybind.Designer.cs

             this.chkFilter = new System.Windows.Forms.CheckBox();
             this.label3 = new System.Windows.Forms.Label();
             this.cboExpansion = new System.Windows.Forms.ComboBox();
+            this.btnGamepad1 = new System.Windows.Forms.Button();
+            this.btnGamepad2 = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // bindViewer
             // chkFourScore
             // 
             this.chkFourScore.AutoSize = true;
-            this.chkFourScore.Location = new System.Drawing.Point(114, 102);
+            this.chkFourScore.Location = new System.Drawing.Point(114, 131);
             this.chkFourScore.Name = "chkFourScore";
             this.chkFourScore.Size = new System.Drawing.Size(78, 17);
             this.chkFourScore.TabIndex = 5;
             // chkFilter
             // 
             this.chkFilter.AutoSize = true;
-            this.chkFilter.Location = new System.Drawing.Point(21, 125);
+            this.chkFilter.Location = new System.Drawing.Point(21, 154);
             this.chkFilter.Name = "chkFilter";
             this.chkFilter.Size = new System.Drawing.Size(171, 17);
             this.chkFilter.TabIndex = 8;
             this.cboExpansion.TabIndex = 9;
             this.cboExpansion.SelectedIndexChanged += new System.EventHandler(this.cboExpansion_SelectedIndexChanged);
             // 
+            // btnGamepad1
+            // 
+            this.btnGamepad1.Location = new System.Drawing.Point(33, 102);
+            this.btnGamepad1.Name = "btnGamepad1";
+            this.btnGamepad1.Size = new System.Drawing.Size(75, 23);
+            this.btnGamepad1.TabIndex = 11;
+            this.btnGamepad1.Text = "Gamepad 1";
+            this.btnGamepad1.UseVisualStyleBackColor = true;
+            this.btnGamepad1.Click += new System.EventHandler(this.btnGamepad1_Click);
+            // 
+            // btnGamepad2
+            // 
+            this.btnGamepad2.Location = new System.Drawing.Point(114, 102);
+            this.btnGamepad2.Name = "btnGamepad2";
+            this.btnGamepad2.Size = new System.Drawing.Size(75, 23);
+            this.btnGamepad2.TabIndex = 12;
+            this.btnGamepad2.Text = "Gamepad 2";
+            this.btnGamepad2.UseVisualStyleBackColor = true;
+            this.btnGamepad2.Click += new System.EventHandler(this.btnGamepad2_Click);
+            // 
             // Keybind
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(538, 449);
+            this.Controls.Add(this.btnGamepad2);
+            this.Controls.Add(this.btnGamepad1);
             this.Controls.Add(this.label3);
             this.Controls.Add(this.cboExpansion);
             this.Controls.Add(this.chkFilter);
         private System.Windows.Forms.CheckBox chkFilter;
         private System.Windows.Forms.Label label3;
         private System.Windows.Forms.ComboBox cboExpansion;
+        private System.Windows.Forms.Button btnGamepad1;
+        private System.Windows.Forms.Button btnGamepad2;
     }
 }

DirectXEmu/Keybind.cs

         public ControllerType portTwo;
         public ControllerType expansion;
 
-        public Keybind(Keybinds keys, ControllerType portOne, ControllerType portTwo, ControllerType expansion, bool fourScore, bool filterIllegalInput)
+        private string inputMode;
+
+        public Keybind(Keybinds keys, ControllerType portOne, ControllerType portTwo, ControllerType expansion, bool fourScore, bool filterIllegalInput, string inputMode)
         {
             this.keys = keys;
             this.fourScore = fourScore;
             this.portOne = portOne;
             this.portTwo = portTwo;
             this.expansion = expansion;
+            this.inputMode = inputMode;
             InitializeComponent();
             chkFourScore.Checked = fourScore;
             chkFilter.Checked = filterIllegalInput;
                     break;
             }
         }
+
+        private void btnGamepad1_Click(object sender, EventArgs e)
+        {
+            PollKey pollKey;
+            Keybinds newKeys = ((Keybinds)bindViewer.SelectedObject);
+            pollKey = new PollKey(newKeys.Player1Up, "Up", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Up = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1Down, "Down", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Down = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1Left, "Left", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Left = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1Right, "Right", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Right = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1A, "A button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1A = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1B, "B button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1B = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1Select, "Select button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Select = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player1Start, "Start button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player1Start = pollKey.newKey;
+            bindViewer.SelectedObject = newKeys;
+        }
+
+        private void btnGamepad2_Click(object sender, EventArgs e)
+        {
+            PollKey pollKey;
+            Keybinds newKeys = ((Keybinds)bindViewer.SelectedObject);
+            pollKey = new PollKey(newKeys.Player2Up, "Up", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Up = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2Down, "Down", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Down = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2Left, "Left", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Left = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2Right, "Right", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Right = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2A, "A button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2A = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2B, "B button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2B = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2Select, "Select button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Select = pollKey.newKey;
+            pollKey = new PollKey(newKeys.Player2Start, "Start button", inputMode);
+            pollKey.ShowDialog();
+            newKeys.Player2Start = pollKey.newKey;
+            bindViewer.SelectedObject = newKeys;
+        }
     }
 }

DirectXEmu/Keybinds.cs

 using System.Text;
 using System.ComponentModel;
 using System.Windows.Forms;
+using System.Windows.Forms.Design;
+using System.Drawing;
+using System.Drawing.Design;
 namespace DirectXEmu
 {
-    public struct Keybinds
+    public struct Keybinds 
     {
         [CategoryAttribute("General")]
-        public Keys Rewind
+        [BrowsableAttribute(true)]
+        public EmuKeys Rewind
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys FastForward
+        [BrowsableAttribute(true)]
+        public EmuKeys FastForward
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys SaveState
+        [BrowsableAttribute(true)]
+        public EmuKeys SaveState
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys LoadState
+        [BrowsableAttribute(true)]
+        public EmuKeys LoadState
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys Pause
+        [BrowsableAttribute(true)]
+        public EmuKeys Pause
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys Reset
+        [BrowsableAttribute(true)]
+        public EmuKeys Reset
         {
             get;
             set;
         }
         [CategoryAttribute("General")]
-        public Keys Power
+        [BrowsableAttribute(true)]
+        public EmuKeys Power
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Up
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Up
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Down
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Down
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Left
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Left
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Right
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Right
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Start
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Start
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1Select
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1Select
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1A
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1A
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1B
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1B
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1TurboA
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1TurboA
         {
             get;
             set;
         }
         [CategoryAttribute("Player 1")]
-        public Keys Player1TurboB
+        [BrowsableAttribute(true)]
+        public EmuKeys Player1TurboB
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Up
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Up
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Down
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Down
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Left
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Left
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Right
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Right
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Start
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Start
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2Select
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2Select
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2A
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2A
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2B
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2B
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2TurboA
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2TurboA
         {
             get;
             set;
         }
         [CategoryAttribute("Player 2")]
-        public Keys Player2TurboB
+        [BrowsableAttribute(true)]
+        public EmuKeys Player2TurboB
         {
             
             get;

DirectXEmu/PollKey.Designer.cs

+namespace DirectXEmu
+{
+    partial class PollKey
+    {
+        /// <summary>
+        /// Required designer variable.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// Clean up any resources being used.
+        /// </summary>
+        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form Designer generated code
+
+        /// <summary>
+        /// Required method for Designer support - do not modify
+        /// the contents of this method with the code editor.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.label2 = new System.Windows.Forms.Label();
+            this.tmrPoll = new System.Windows.Forms.Timer(this.components);
+            this.lblMessage = new System.Windows.Forms.Label();
+            this.SuspendLayout();
+            // 
+            // label2
+            // 
+            this.label2.Location = new System.Drawing.Point(12, 17);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(171, 13);
+            this.label2.TabIndex = 3;
+            this.label2.Text = "Press a key for...";
+            this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
+            // 
+            // tmrPoll
+            // 
+            this.tmrPoll.Interval = 16;
+            this.tmrPoll.Tick += new System.EventHandler(this.tmrPoll_Tick);
+            // 
+            // lblMessage
+            // 
+            this.lblMessage.Location = new System.Drawing.Point(12, 37);
+            this.lblMessage.Name = "lblMessage";
+            this.lblMessage.Size = new System.Drawing.Size(171, 23);
+            this.lblMessage.TabIndex = 4;
+            this.lblMessage.TextAlign = System.Drawing.ContentAlignment.TopCenter;
+            // 
+            // PollKey
+            // 
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+            this.ClientSize = new System.Drawing.Size(195, 78);
+            this.Controls.Add(this.lblMessage);
+            this.Controls.Add(this.label2);
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+            this.KeyPreview = true;
+            this.MaximizeBox = false;
+            this.MinimizeBox = false;
+            this.Name = "PollKey";
+            this.ShowIcon = false;
+            this.ShowInTaskbar = false;
+            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+            this.Text = "Bind Key";
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.PollKey_FormClosing);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.Timer tmrPoll;
+        private System.Windows.Forms.Label lblMessage;
+    }
+}

DirectXEmu/PollKey.cs

+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+using System.Threading;
+
+namespace DirectXEmu
+{
+    public partial class PollKey : Form
+    {
+        public EmuKeys oldKey;
+        public EmuKeys newKey;
+        IInput input;
+        public PollKey(EmuKeys oldKey, string message, string inputMode)
+        {
+            InitializeComponent();
+            switch (inputMode)
+            {
+                default:
+                case "Win":
+                    input = new WinInput(this, this);
+                    break;
+#if !NO_DX
+                case "DX":
+                    input = new DXInput(this);
+                    break;
+                case "XIn":
+                    input = new XInInput();
+                    break;
+#endif
+                case "Null":
+                    input = new NullInput();
+                    break;
+            }
+            lblMessage.Text = message;
+            input.Create();
+            input.InputEvent += new InputHandler(input_InputEvent);
+            input.InputScalerEvent += new InputScalerHandler(input_InputScalerEvent);
+            this.oldKey = this.newKey = oldKey;
+            tmrPoll.Enabled = true;
+        }
+
+        void input_InputScalerEvent(EmuKeys key, int value)
+        {
+        }
+
+        void input_InputEvent(EmuKeys key, bool pressed)
+        {
+            if (key != EmuKeys.None && pressed)
+            {
+                newKey = key;
+                DialogResult = System.Windows.Forms.DialogResult.OK;
+            }
+        }
+        private void PollKey_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            tmrPoll.Enabled = false;
+            Thread.Sleep(50);
+            input.Destroy();
+        }
+
+        private void tmrPoll_Tick(object sender, EventArgs e)
+        {
+            input.MainLoop();
+        }
+    }
+}

DirectXEmu/PollKey.resx

+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="tmrPoll.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+</root>

DirectXEmu/Program.cs

                 playMovie = !Fm2Reader();
                 if (fm2Reset)
                 {
-                    cpu.Reset();
+                    cpu.Power();
                     fm2Reset = false;
                 }
                 if (!playMovie)
                     break;
             }
             input.Create();
-            input.KeyDownEvent += new KeyHandler(input_KeyDownEvent);
-            input.KeyUpEvent += new KeyHandler(input_KeyUpEvent);
-            input.MouseMoveEvent += new MouseHandler(input_MouseMoveEvent);
-            input.MouseDownEvent += new MouseHandler(input_MouseDownEvent);
-            input.MouseUpEvent += new MouseHandler(input_MouseUpEvent);
+            input.InputEvent += new InputHandler(input_InputEvent);
+            input.InputScalerEvent += new InputScalerHandler(input_InputScalerEvent);
+        }
+
+        void input_InputScalerEvent(EmuKeys key, int value)
+        {
+            switch (key)
+            {
+                case EmuKeys.MouseX:
+                    Point tmpPointX = surfaceControl.PointToClient(new Point(value, 0));
+                    tmpPointX.X = (int)((256 * tmpPointX.X) / (surfaceControl.Width * 1.0));
+                    if (tmpPointX.X < 0)
+                        tmpPointX.X = 0;
+                    else if (tmpPointX.X >= 256)
+                        tmpPointX.X = 256 - 1;
+                    player1.x = (byte)tmpPointX.X;
+                    player2.x = player1.x;
+                    break;
+                case EmuKeys.MouseY:
+                    Point tmpPointY = surfaceControl.PointToClient(new Point(0, value));
+                    tmpPointY.Y = (int)((240 * tmpPointY.Y) / (surfaceControl.Height * 1.0));
+                    if (tmpPointY.Y < 0)
+                        tmpPointY.Y = 0;
+                    else if (tmpPointY.Y >= 240)
+                        tmpPointY.Y = 240 - 1;
+                    player1.y = (byte)tmpPointY.Y;
+                    player2.y = player1.y;
+                    break;
+            }
+        }
+
+        void input_InputEvent(EmuKeys key, bool pressed)
+        {
+            if (key == keyBindings.Player1A)
+            {
+                player1Pressed.a = pressed;
+            }
+            else if (key == keyBindings.Player1TurboA)
+            {
+                player1A.on = pressed;
+                if(!pressed)
+                    player1A.count = 1;
+            }
+            else if (key == keyBindings.Player1B)
+            {
+                player1Pressed.b = pressed;
+            }
+            else if (key == keyBindings.Player1TurboB)
+            {
+                player1B.on = pressed;
+                if (!pressed)
+                    player1B.count = 1;
+            }
+            else if (key == keyBindings.Player1Select)
+            {
+                player1Pressed.select = pressed;
+            }
+            else if (key == keyBindings.Player1Start)
+            {
+                player1Pressed.start = pressed;
+            }
+            else if (key == keyBindings.Player1Up)
+            {
+                player1Pressed.up = pressed;
+            }
+            else if (key == keyBindings.Player1Down)
+            {
+                player1Pressed.down = pressed;
+            }
+            else if (key == keyBindings.Player1Left)
+            {
+                player1Pressed.left = pressed;
+                if (cpu != null && !pressed)
+                    cpu.NSFPreviousSong();
+            }
+            else if (key == keyBindings.Player1Right)
+            {
+                player1Pressed.right = pressed;
+                if (cpu != null && !pressed)
+                    cpu.NSFNextSong();
+            }
+            else if (key == EmuKeys.Mouse1)
+            {
+                player1.triggerPulled = pressed;
+                player2.triggerPulled = pressed;
+            }
+            else if (key == keyBindings.Player2A)
+            {
+                player2Pressed.a = pressed;
+            }
+            else if (key == keyBindings.Player2TurboA)
+            {
+                player2A.on = pressed;
+                if (!pressed)
+                    player2A.count = 1;
+            }
+            else if (key == keyBindings.Player2B)
+            {
+                player2Pressed.b = pressed;
+            }
+            else if (key == keyBindings.Player2TurboB)
+            {
+                player2B.on = pressed;
+                if (!pressed)
+                    player2B.count = 1;
+            }
+            else if (key == keyBindings.Player2Select)
+            {
+                player2Pressed.select = pressed;
+            }
+            else if (key == keyBindings.Player2Start)
+            {
+                player2Pressed.start = pressed;
+            }
+            else if (key == keyBindings.Player2Up)
+            {
+                player2Pressed.up = pressed;
+            }
+            else if (key == keyBindings.Player2Down)
+            {
+                player2Pressed.down = pressed;
+            }
+            else if (key == keyBindings.Player2Left)
+            {
+                player2Pressed.left = pressed;
+            }
+            else if (key == keyBindings.Player2Right)
+            {
+                player2Pressed.right = pressed;
+            }
+            else if (key == EmuKeys.Q)
+            {
+                controlStrobe = pressed;
+            }
+            else if (key == keyBindings.SaveState)
+            {
+                if (!pressed)
+                    this.storeState = true;
+            }
+            else if (key == keyBindings.LoadState)
+            {
+                if (!pressed)
+                    this.loadState = true;
+            }
+            else if (key == keyBindings.Rewind)
+            {
+                rewinding = pressed;
+            }
+            else if (key == keyBindings.FastForward)
+            {
+                frameSkipper = pressed ? maxFrameSkip : 1;
+            }
+            else if (key == EmuKeys.F2)
+            {
+                player1.coin = pressed;
+            }
+            else if (key == EmuKeys.F3)
+            {
+                player2.coin = pressed;
+            }
+            else if (key == keyBindings.Pause)
+            {
+                if (!pressed)