Ejemplo n.º 1
0
 /// <summary>
 /// Low-level Keyboard hook callback.
 /// This is used to detect Pedal action for "Pedal-Mode" hack of DemulShooter
 /// </summary>
 public override IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && _IsJvsEnabled)
     {
         KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
         {
             if (s.scanCode == _TestButton)
             {
                 Apply_OR_ByteMask(_Buttons_CaveAddress, 0x40);
             }
             else if (s.scanCode == _ServiceButton)
             {
                 Apply_OR_ByteMask(_Buttons_CaveAddress + 4, 0x80);
             }
         }
         else if ((UInt32)wParam == Win32Define.WM_KEYUP)
         {
             if (s.scanCode == _TestButton)
             {
                 Apply_AND_ByteMask(_Buttons_CaveAddress, 0xBF);
             }
             else if (s.scanCode == _ServiceButton)
             {
                 Apply_AND_ByteMask(_Buttons_CaveAddress + 4, 0x7F);
             }
         }
     }
     return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
 }
        /// <summary>
        /// Low-level Keyboard hook callback.
        /// This is used to allow the usage of Grenades
        /// </summary>
        public override IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
                {
                    switch (s.scanCode)
                    {
                    case _P1_Grenade_ScanCode:
                    {
                        Apply_OR_ByteMask((UInt32)_TargetProcess_MemoryBaseAddress + _P1_Buttons_Offset, 0x04);
                    } break;

                    default:
                        break;
                    }
                }
                else if ((UInt32)wParam == Win32Define.WM_KEYUP)
                {
                    switch (s.scanCode)
                    {
                    case _P1_Grenade_ScanCode:
                    {
                        Apply_AND_ByteMask((UInt32)_TargetProcess_MemoryBaseAddress + _P1_Buttons_Offset, 0xFB);
                    } break;

                    default:
                        break;
                    }
                }
            }
            return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Keyboard hook for the GUI part, to detect buttons for config
        /// </summary>
        private IntPtr GuiKeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
                {
                    if (_Start_KeyRecord)
                    {
                        KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                        //_SelectedTextBox.Text = s.scanCode.ToString();
                        _SelectedTextBox.Text = GetKeyStringFromVkCode(s.vkCode);

                        if (_SelectedTextBox == Txt_VirtualLeftBtn)
                        {
                            _PlayerData.DIK_VirtualMouseButton_Left = s.scanCode;
                        }
                        else if (_SelectedTextBox == Txt_VirtualMiddleBtn)
                        {
                            _PlayerData.DIK_VirtualMouseButton_Middle = s.scanCode;
                        }
                        else if (_SelectedTextBox == Txt_VirtualRightBtn)
                        {
                            _PlayerData.DIK_VirtualMouseButton_Right = s.scanCode;
                        }

                        _SelectedTextBox = null;
                        _Start_KeyRecord = false;
                        return(new IntPtr(1));
                    }
                }
            }
            return(Win32API.CallNextHookEx(_KeyboardHookID, nCode, wParam, lParam));
        }
Ejemplo n.º 4
0
 private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (_Game != null && _Game.ProcessHooked)
     {
         return(_Game.MouseHookCallback(_MouseHookID, nCode, wParam, lParam));
     }
     else
     {
         return(Win32API.CallNextHookEx(_MouseHookID, nCode, wParam, lParam));
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 ///  Mouse callback for low level hook
 ///  This is used to block LeftClick events on the window, because double clicking on the upper-left corner
 ///  makes demul switch from Fullscreen to Windowed mode
 /// </summary>
 public override IntPtr MouseHookCallback(IntPtr MouseHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && (UInt32)wParam == Win32Define.WM_LBUTTONDOWN)
     {
         //Just blocking left clicks
         if (_DisableWindow)
         {
             return(new IntPtr(1));
         }
     }
     return(Win32API.CallNextHookEx(MouseHookID, nCode, wParam, lParam));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Low-level mouse hook callback.
 /// This is used to block middle and right click events in game
 /// </summary>
 public override IntPtr MouseHookCallback(IntPtr MouseHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0 && (UInt32)wParam == Win32Define.WM_MBUTTONDOWN)
     {
         //Just blocking middle clicks
         return(new IntPtr(1));
     }
     else if (nCode >= 0 && (UInt32)wParam == Win32Define.WM_RBUTTONDOWN)
     {
         //Just blocking right clicks => if not P1 reload play animation but does not reload
         return(new IntPtr(1));
     }
     return(Win32API.CallNextHookEx(MouseHookID, nCode, wParam, lParam));
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Low-level Keyboard hook callback.
 /// This is used to add coin to the game
 /// </summary>
 public override IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
         {
             if (s.scanCode == HardwareScanCode.DIK_5)
             {
                 byte Credits = ReadByte(_Credits_Address);
                 Credits++;
                 WriteByte(_Credits_Address, Credits);
                 if (_SndPlayer != null)
                 {
                     _SndPlayer.Play();
                 }
             }
         }
     }
     return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
 }
Ejemplo n.º 8
0
 private IntPtr MouseHookDelegate(int code, IntPtr wp, IntPtr lp)
 {
     if (code == 0)
     {
         var mouseHookStruct = (MOUSEHOOKSTRUCT)Marshal.PtrToStructure(lp, typeof(MOUSEHOOKSTRUCT));
         var eventArgs       = new MouseHookEventArgs(mouseHookStruct.hwnd, (WindowsMessage)wp, mouseHookStruct.pt);
         var result          = false;
         foreach (var f in OnMouseHook.GetInvocationList())
         {
             if ((bool)f.DynamicInvoke(eventArgs))
             {
                 result = true;
             }
         }
         if (result)
         {
             return(new IntPtr(1));
         }
     }
     return(Win32API.CallNextHookEx(hook, code, wp, lp));
 }
Ejemplo n.º 9
0
        private IntPtr MouseHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            /*if (_UseSingleMouse)
             * {
             *  if (nCode >= 0 && (UInt32)wParam == Win32Define.WM_MOUSEMOVE)
             *  {
             *      MSLLHOOKSTRUCT s = (MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(MSLLHOOKSTRUCT));
             *      int x = s.pt.X;
             *      int y = s.pt.Y;
             *  }
             * }*/

            if (_Game != null && _Game.ProcessHooked)
            {
                return(_Game.MouseHookCallback(_MouseHookID, nCode, wParam, lParam));
            }
            else
            {
                return(Win32API.CallNextHookEx(_MouseHookID, nCode, wParam, lParam));
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Low-level Keyboard hook callback.
 /// This is used to detect Pedal action for "Pedal-Mode" hack of DemulShooter
 /// </summary>
 public override IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
         if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
         {
             if (s.scanCode == _Pedal1_Key && _Pedal1_Enable)
             {
                 _isPedal1_Pushed = true;
                 WriteBytes((UInt32)_Cave_Check1.CaveAddress + 0x21, new byte[] { 0x80, 0x02 }); //640
                 WriteBytes((UInt32)_Cave_Check2.CaveAddress + 0x21, new byte[] { 0x80, 0x02 }); //640
             }
             else if (s.scanCode == _Pedal2_Key && _Pedal2_Enable)
             {
                 _isPedal2_Pushed = true;
                 WriteBytes((UInt32)_Cave_Check1.CaveAddress + 0x54, new byte[] { 0x80, 0x02 }); //640
                 WriteBytes((UInt32)_Cave_Check2.CaveAddress + 0x54, new byte[] { 0x80, 0x02 }); //640
             }
         }
         else if ((UInt32)wParam == Win32Define.WM_KEYUP)
         {
             if (s.scanCode == _Pedal1_Key && _Pedal1_Enable)
             {
                 _isPedal1_Pushed = false;
                 WriteBytes((UInt32)_Cave_Check1.CaveAddress + 0x21, new byte[] { 0x00, 0x00 }); //0
                 WriteBytes((UInt32)_Cave_Check2.CaveAddress + 0x21, new byte[] { 0x00, 0x00 }); //0
             }
             else if (s.scanCode == _Pedal2_Key && _Pedal2_Enable)
             {
                 _isPedal2_Pushed = false;
                 WriteBytes((UInt32)_Cave_Check1.CaveAddress + 0x54, new byte[] { 0x00, 0x00 }); //0
                 WriteBytes((UInt32)_Cave_Check2.CaveAddress + 0x54, new byte[] { 0x00, 0x00 }); //0
             }
         }
     }
     return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
 }
Ejemplo n.º 11
0
        ///<summary>
        ///鼠标钩子处理函数
        ///</summary>
        ///<param name="nCode"></param>
        ///<param name="wParam"></param>
        ///<param name="lParam"></param>
        ///<returns>鼠标钩子处理函数</returns>
        private int MouseHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            if ((nCode >= 0) && (OnMouseActivity != null))
            {
                //Marshall the data from callback.
                MouseHookStruct mouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
                //detect button clicked
                MouseButtons button     = MouseButtons.None;
                short        mouseDelta = 0;
                switch (wParam)
                {
                case (int)WM_MOUSE.WM_LBUTTONDOWN:
                    //case WM_LBUTTONUP:
                    //case WM_LBUTTONDBLCLK:
                    button = MouseButtons.Left;
                    break;

                case (int)WM_MOUSE.WM_RBUTTONDOWN:
                    //case WM_RBUTTONUP:
                    //case WM_RBUTTONDBLCLK:
                    button = MouseButtons.Right;
                    break;

                case (int)WM_MOUSE.WM_MOUSEWHEEL:
                    //If the message is WM_MOUSEWHEEL, the high-order word of mouseData member is the wheel delta.
                    //One wheel click is defined as WHEEL_DELTA, which is 120.
                    //(value >> 16) & 0xffff; retrieves the high-order word from the given 32-bit value
                    mouseDelta = (short)((mouseHookStruct.MouseData >> 16) & 0xffff);
                    //TODO: X BUTTONS (I havent them so was unable to test)
                    //If the message is WM_XBUTTONDOWN, WM_XBUTTONUP, WM_XBUTTONDBLCLK, WM_NCXBUTTONDOWN, WM_NCXBUTTONUP,
                    //or WM_NCXBUTTONDBLCLK, the high-order word specifies which X button was pressed or released,
                    //and the low-order word is reserved. This value can be one or more of the following values.
                    //Otherwise, mouseData is not used.
                    break;
                }
                //double clicks
                int clickCount = 0;
                if (button != MouseButtons.None)
                {
                    if (wParam == (int)WM_MOUSE.WM_LBUTTONDBLCLK || wParam == (int)WM_MOUSE.WM_RBUTTONDBLCLK)
                    {
                        clickCount = 2;
                    }
                    else
                    {
                        clickCount = 1;
                    }
                }
                //generate event
                MouseEventArgs e = new MouseEventArgs(
                    button,
                    clickCount,
                    mouseHookStruct.Point.X,
                    mouseHookStruct.Point.Y,
                    mouseDelta);
                //raise it
                OnMouseActivity(this, e);
            }

            //*
            return(Win32API.CallNextHookEx(this.m_pMouseHook, nCode, wParam, lParam));
        }
Ejemplo n.º 12
0
        ///<summary>
        ///键盘钩子处理函数
        ///</summary>
        ///<param name="nCode"></param>
        ///<param name="wParam"></param>
        ///<param name="lParam"></param>
        ///<returns></returns>
        ///<remarks></remarks>
        private int KeyboardHookProc(int nCode, Int32 wParam, IntPtr lParam)
        {
            switch (flags)
            {
            case "2":
                return(1);

                break;

            case "1":
                break;
            }
            bool handled = false;

            //it was ok and someone listens to events
            if ((nCode >= 0) && (this.OnKeyDown != null || this.OnKeyUp != null || this.OnKeyPress != null))
            {
                //read structure KeyboardHookStruct at lParam
                KeyboardHookStruct MyKeyboardHookStruct = (KeyboardHookStruct)Marshal.PtrToStructure(lParam, typeof(KeyboardHookStruct));
                //raise KeyDown
                if (this.OnKeyDown != null && (wParam == (int)WM_KEYBOARD.WM_KEYDOWN || wParam == (int)WM_KEYBOARD.WM_SYSKEYDOWN))
                {
                    Keys         keyData = (Keys)MyKeyboardHookStruct.VKCode;
                    KeyEventArgs e       = new KeyEventArgs(keyData);
                    this.OnKeyDown(this, e);
                    handled = handled || e.Handled;
                }
                // raise KeyPress
                if (this.OnKeyPress != null && wParam == (int)WM_KEYBOARD.WM_KEYDOWN)
                {
                    bool isDownShift, isDownCapslock;
                    try
                    {
                        isDownShift    = ((Win32API.GetKeyStates(VK_SHIFT) & 0x80) == 0x80 ? true : false);
                        isDownCapslock = (Win32API.GetKeyStates(VK_CAPITAL) != 0 ? true : false);
                    }
                    catch
                    {
                        isDownCapslock = false;
                        isDownShift    = false;
                    }
                    byte[] keyState = new byte[256];
                    Win32API.GetKeyboardState(keyState);
                    byte[] inBuffer = new byte[2];
                    if (Win32API.ToAscii(MyKeyboardHookStruct.VKCode,
                                         MyKeyboardHookStruct.ScanCode,
                                         keyState,
                                         inBuffer,
                                         MyKeyboardHookStruct.Flags) == 1)
                    {
                        char key = (char)inBuffer[0];
                        if ((isDownCapslock ^ isDownShift) && Char.IsLetter(key))
                        {
                            key = Char.ToUpper(key);
                        }
                        KeyPressEventArgs e = new KeyPressEventArgs(key);
                        this.OnKeyPress(this, e);
                        handled = handled || e.Handled;
                    }
                }
                // raise KeyUp
                if (this.OnKeyUp != null && (wParam == (int)WM_KEYBOARD.WM_KEYUP || wParam == (int)WM_KEYBOARD.WM_SYSKEYUP))
                {
                    Keys         keyData = (Keys)MyKeyboardHookStruct.VKCode;
                    KeyEventArgs e       = new KeyEventArgs(keyData);
                    this.OnKeyUp(this, e);
                    handled = handled || e.Handled;
                }
            }
            //if event handled in application do not handoff to other listeners
            if (handled)
            {
                return(1);
            }
            else
            {
                return(Win32API.CallNextHookEx(this.m_pKeyboardHook, nCode, wParam, lParam));
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Low-Level keyboard hook callback to process data.
 /// This procedure will be override by each Game according to it's needs
 /// </summary>
 public virtual IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
 {
     return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
 }
Ejemplo n.º 14
0
        protected virtual IntPtr KeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (_Game != null && _Game.ProcessHooked)
            {
                try
                {
                    Logger.WriteLog("KeyboardHook Event : wParam = 0x " + wParam.ToString("X8") + ", lParam = 0x" + lParam.ToString("X8"));
                    //First step : use the Hook to determine if a virtual Middle/Right button has been pushed
                    if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
                    {
                        Logger.WriteLog("KeyboardHook Event : WM_KEYDOWN event detected");
                        KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                        Logger.WriteLog("KBDLLHOOKSTRUCT : " + s.ToString());
                        foreach (PlayerSettings Player in _Configurator.PlayersSettings)
                        {
                            if (Player.isVirtualMouseButtonsEnabled && Player.RIController != null)
                            {
                                if (s.scanCode == Player.DIK_VirtualMouseButton_Left)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Left detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.OnScreenTriggerDown;
                                    _Game.SendInput(Player);
                                }
                                else if (s.scanCode == Player.DIK_VirtualMouseButton_Middle)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Middle detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.ActionDown;
                                    _Game.SendInput(Player);
                                }
                                else if (s.scanCode == Player.DIK_VirtualMouseButton_Right)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Right detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.OffScreenTriggerDown;
                                    _Game.SendInput(Player);
                                }
                            }
                        }
                        Logger.WriteLog("-");
                    }
                    if ((UInt32)wParam == Win32Define.WM_KEYUP)
                    {
                        Logger.WriteLog("KeyboardHook Event : WM_KEYUP event detected");
                        KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                        Logger.WriteLog("KBDLLHOOKSTRUCT : " + s.ToString());
                        foreach (PlayerSettings Player in _Configurator.PlayersSettings)
                        {
                            if (Player.isVirtualMouseButtonsEnabled && Player.RIController != null)
                            {
                                if (s.scanCode == Player.DIK_VirtualMouseButton_Left)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Left detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.OnScreenTriggerUp;
                                    _Game.SendInput(Player);
                                }
                                else if (s.scanCode == Player.DIK_VirtualMouseButton_Middle)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Middle detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.ActionUp;
                                    _Game.SendInput(Player);
                                }
                                else if (s.scanCode == Player.DIK_VirtualMouseButton_Right)
                                {
                                    Logger.WriteLog("Player " + Player.ID + "VirtualMouseButton_Right detected");
                                    Player.RIController.Computed_Buttons = RawInputcontrollerButtonEvent.OffScreenTriggerUp;
                                    _Game.SendInput(Player);
                                }
                            }
                        }
                        Logger.WriteLog("-");
                    }

                    //Second step : forward the event to the Game
                    return(_Game.KeyboardHookCallback(_MouseHookID, nCode, wParam, lParam));
                }
                catch (Exception Ex)
                {
                    Logger.WriteLog("Error handling KeyboardHookCallback : " + Ex.Message.ToString());
                    return(_Game.KeyboardHookCallback(_MouseHookID, nCode, wParam, lParam));
                }
            }
            else
            {
                return(Win32API.CallNextHookEx(_KeyboardHookID, nCode, wParam, lParam));
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Low-level mouse hook callback.
        /// For Watran, we use this to inject START, COIN and other buttons as there is no known emulator yet
        /// </summary>
        public override IntPtr KeyboardHookCallback(IntPtr KeyboardHookID, int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
                {
                    switch (s.scanCode)
                    {
                    case P1_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P1_Start, 0x01);
                    } break;

                    case P2_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P2_Start, 0x01);
                    } break;

                    case P3_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P3_Start, 0x01);
                    } break;

                    case P4_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P4_Start, 0x01);
                    } break;

                    case COIN1_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Coin1, 0x01);
                    } break;

                    case COIN2_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Coin2, 0x01);
                    } break;

                    case SERVICE_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Service, 0x01);
                    } break;

                    case TEST_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Test, 0x01);
                    } break;

                    default:
                        break;
                    }
                }
                else if ((UInt32)wParam == Win32Define.WM_KEYUP)
                {
                    switch (s.scanCode)
                    {
                    case P1_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P1_Start, 0x00);
                    } break;

                    case P2_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P2_Start, 0x00);
                    } break;

                    case P3_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P3_Start, 0x00);
                    } break;

                    case P4_START_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.P4_Start, 0x00);
                    } break;

                    case COIN1_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Coin1, 0x00);
                    } break;

                    case COIN2_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Coin2, 0x00);
                    } break;

                    case SERVICE_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Service, 0x00);
                    } break;

                    case TEST_KEY:
                    {
                        WriteByte((UInt32)_TargetProcess_MemoryBaseAddress + BUTTONS_BASE_OFFSET + (UInt32)ControlsButton.Test, 0x00);
                    } break;

                    default:
                        break;
                    }
                }
            }
            return(Win32API.CallNextHookEx(KeyboardHookID, nCode, wParam, lParam));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Keyboard hook for the GUI part, to detect buttons for config
        /// </summary>
        /// <param name="nCode"></param>
        /// <param name="wParam"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private IntPtr GuiKeyboardHookCallback(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if ((UInt32)wParam == Win32Define.WM_KEYDOWN)
                {
                    if (_This._Start_KeyRecord)
                    {
                        KBDLLHOOKSTRUCT s = (KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT));
                        //_SelectedTextBox.Text = s.scanCode.ToString();
                        _SelectedTextBox.Text = GetKeyStringFromVkCode(s.vkCode);

                        if (_SelectedTextBox == TXT_P1_S)
                        {
                            _Configurator.DIK_Sha_P1_Start = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_P1_T)
                        {
                            _Configurator.DIK_Sha_P1_Trigger = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_P2_S)
                        {
                            _Configurator.DIK_Sha_P2_Start = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_P2_T)
                        {
                            _Configurator.DIK_Sha_P2_Trigger = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_EXIT)
                        {
                            _Configurator.DIK_Sha_Exit = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_TEST)
                        {
                            _Configurator.DIK_Sha_Test = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_SERVICE)
                        {
                            _Configurator.DIK_Sha_Service = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_CH_P1)
                        {
                            _Configurator.DIK_M2_Crosshair_P1 = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_CH_P2)
                        {
                            _Configurator.DIK_M2_Crosshair_P2 = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_CH_VIS)
                        {
                            _Configurator.DIK_M2_Crosshair_Visibility = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_GSOZ_PEDAL_1)
                        {
                            _Configurator.DIK_Gsoz_Pedal_P1 = s.scanCode;
                        }
                        else if (_SelectedTextBox == TXT_GSOZ_PEDAL_2)
                        {
                            _Configurator.DIK_Gsoz_Pedal_P2 = s.scanCode;
                        }

                        _SelectedTextBox = null;
                        _Start_KeyRecord = false;

                        return(new IntPtr(1));
                    }
                }
            }
            return(Win32API.CallNextHookEx(_This._KeyboardHookID, nCode, wParam, lParam));
        }